fix(tests): Fix abort of Task test on Linux
Not sure exactly what caused the issue, though I suppose using QThread's exec instead of our own thingie is nice. I can't remember why I didn't use that before, so I hope there's no issue with that! :^) Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
71e73bb6f8
commit
b8b8c8d4ac
@ -50,15 +50,11 @@ class BigConcurrentTask : public ConcurrentTask {
|
|||||||
class BigConcurrentTaskThread : public QThread {
|
class BigConcurrentTaskThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
QTimer m_deadline;
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
QTimer deadline;
|
|
||||||
BigConcurrentTask big_task;
|
BigConcurrentTask big_task;
|
||||||
deadline.setInterval(10000);
|
m_deadline.setInterval(10000);
|
||||||
bool* pt_deadline = &passed_the_deadline;
|
|
||||||
QMetaObject::Connection conn = connect(&deadline, &QTimer::timeout, this, [pt_deadline] { *pt_deadline = true; });
|
|
||||||
deadline.start();
|
|
||||||
|
|
||||||
// NOTE: Arbitrary value that manages to trigger a problem when there is one.
|
// NOTE: Arbitrary value that manages to trigger a problem when there is one.
|
||||||
// Considering each tasks, in a problematic state, adds 1024 * 4 bytes to the stack,
|
// Considering each tasks, in a problematic state, adds 1024 * 4 bytes to the stack,
|
||||||
@ -69,23 +65,17 @@ class BigConcurrentTaskThread : public QThread {
|
|||||||
big_task.addTask(sub_task);
|
big_task.addTask(sub_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect(&big_task, &Task::finished, this, &QThread::quit);
|
||||||
|
connect(&m_deadline, &QTimer::timeout, this, [&] { passed_the_deadline = true; quit(); });
|
||||||
|
|
||||||
|
m_deadline.start();
|
||||||
big_task.run();
|
big_task.run();
|
||||||
|
|
||||||
while (!big_task.isFinished() && !passed_the_deadline)
|
exec();
|
||||||
QCoreApplication::processEvents();
|
|
||||||
// don't fire timer after this point
|
|
||||||
disconnect(conn);
|
|
||||||
if (deadline.isActive())
|
|
||||||
deadline.stop();
|
|
||||||
// task finished
|
|
||||||
emit finished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool passed_the_deadline = false;
|
bool passed_the_deadline = false;
|
||||||
|
|
||||||
signals:
|
|
||||||
void finished();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TaskTest : public QObject {
|
class TaskTest : public QObject {
|
||||||
@ -253,7 +243,7 @@ class TaskTest : public QObject {
|
|||||||
{
|
{
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
||||||
BigConcurrentTaskThread thread{};
|
BigConcurrentTaskThread thread;
|
||||||
|
|
||||||
connect(&thread, &BigConcurrentTaskThread::finished, &loop, &QEventLoop::quit);
|
connect(&thread, &BigConcurrentTaskThread::finished, &loop, &QEventLoop::quit);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user