aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2023-01-17 22:51:54 -0300
committerflow <flowlnlnln@gmail.com>2023-01-18 16:23:30 -0300
commitad74fedfba45fe0f36ff387e586b21d4ede8ca83 (patch)
treeb84c332d86d357a231791a9e356ac7d1d8efa370 /tests
parent1a35fec1341323950eb5cb4ee1d2791b2241db67 (diff)
downloadPrismLauncher-ad74fedfba45fe0f36ff387e586b21d4ede8ca83.tar.gz
PrismLauncher-ad74fedfba45fe0f36ff387e586b21d4ede8ca83.tar.bz2
PrismLauncher-ad74fedfba45fe0f36ff387e586b21d4ede8ca83.zip
feat(tests): add test for stack overflow in ConcurrentTask
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Task_test.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp
index 80bba02f..5d906851 100644
--- a/tests/Task_test.cpp
+++ b/tests/Task_test.cpp
@@ -1,4 +1,6 @@
#include <QTest>
+#include <QTimer>
+#include <QThread>
#include <tasks/ConcurrentTask.h>
#include <tasks/MultipleOptionsTask.h>
@@ -11,6 +13,9 @@ class BasicTask : public Task {
friend class TaskTest;
+ public:
+ BasicTask(bool show_debug_log = true) : Task(nullptr, show_debug_log) {}
+
private:
void executeTask() override
{
@@ -30,6 +35,41 @@ class BasicTask_MultiStep : public Task {
void executeTask() override {};
};
+class BigConcurrentTask : public QThread {
+ Q_OBJECT
+
+ ConcurrentTask big_task;
+
+ void run() override
+ {
+ QTimer deadline;
+ deadline.setInterval(10000);
+ connect(&deadline, &QTimer::timeout, this, [this]{ passed_the_deadline = true; });
+ deadline.start();
+
+ static const unsigned s_num_tasks = 1 << 14;
+ auto sub_tasks = new BasicTask*[s_num_tasks];
+
+ for (unsigned i = 0; i < s_num_tasks; i++) {
+ sub_tasks[i] = new BasicTask(false);
+ big_task.addTask(sub_tasks[i]);
+ }
+
+ big_task.run();
+
+ while (!big_task.isFinished() && !passed_the_deadline)
+ QCoreApplication::processEvents();
+
+ emit finished();
+ }
+
+ public:
+ bool passed_the_deadline = false;
+
+ signals:
+ void finished();
+};
+
class TaskTest : public QObject {
Q_OBJECT
@@ -183,6 +223,23 @@ class TaskTest : public QObject {
return t.isFinished();
}, 1000), "Task didn't finish as it should.");
}
+
+ void test_stackOverflowInConcurrentTask()
+ {
+ QEventLoop loop;
+
+ auto thread = new BigConcurrentTask;
+ thread->setStackSize(32 * 1024);
+
+ connect(thread, &BigConcurrentTask::finished, &loop, &QEventLoop::quit);
+
+ thread->start();
+
+ loop.exec();
+
+ QVERIFY(!thread->passed_the_deadline);
+ thread->deleteLater();
+ }
};
QTEST_GUILESS_MAIN(TaskTest)