diff options
author | flow <flowlnlnln@gmail.com> | 2023-07-06 06:38:36 -0300 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2023-07-06 09:49:07 -0700 |
commit | b8b8c8d4acab8c794555956fae699d5706e222f3 (patch) | |
tree | e8109655dac0b6060160b006ca5d64c70a508539 /tests | |
parent | 71e73bb6f8c4a695e39f0c0fec901d8a5e5121b3 (diff) | |
download | PrismLauncher-b8b8c8d4acab8c794555956fae699d5706e222f3.tar.gz PrismLauncher-b8b8c8d4acab8c794555956fae699d5706e222f3.tar.bz2 PrismLauncher-b8b8c8d4acab8c794555956fae699d5706e222f3.zip |
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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Task_test.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp index 00d06794..c59d4bb7 100644 --- a/tests/Task_test.cpp +++ b/tests/Task_test.cpp @@ -50,15 +50,11 @@ class BigConcurrentTask : public ConcurrentTask { class BigConcurrentTaskThread : public QThread { Q_OBJECT - + QTimer m_deadline; void run() override { - QTimer deadline; BigConcurrentTask big_task; - deadline.setInterval(10000); - bool* pt_deadline = &passed_the_deadline; - QMetaObject::Connection conn = connect(&deadline, &QTimer::timeout, this, [pt_deadline] { *pt_deadline = true; }); - deadline.start(); + m_deadline.setInterval(10000); // 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, @@ -69,23 +65,17 @@ class BigConcurrentTaskThread : public QThread { 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(); - while (!big_task.isFinished() && !passed_the_deadline) - QCoreApplication::processEvents(); - // don't fire timer after this point - disconnect(conn); - if (deadline.isActive()) - deadline.stop(); - // task finished - emit finished(); + exec(); } public: bool passed_the_deadline = false; - - signals: - void finished(); }; class TaskTest : public QObject { @@ -253,7 +243,7 @@ class TaskTest : public QObject { { QEventLoop loop; - BigConcurrentTaskThread thread{}; + BigConcurrentTaskThread thread; connect(&thread, &BigConcurrentTaskThread::finished, &loop, &QEventLoop::quit); |