From 14a4fd2ed3732ca19c4bb6275f2e09c462825043 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Wed, 6 Dec 2023 20:51:20 -0800 Subject: [PATCH] tests/taskmanager: check that sleepSeconds() actually waits --- tests/taskmanager/test-taskmanager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/taskmanager/test-taskmanager.cpp b/tests/taskmanager/test-taskmanager.cpp index 26d14c48..a89c50ae 100644 --- a/tests/taskmanager/test-taskmanager.cpp +++ b/tests/taskmanager/test-taskmanager.cpp @@ -5,6 +5,7 @@ WARNINGS_DISABLE #include #include #include +#include #include #include #include @@ -226,6 +227,9 @@ void TestTaskManager::sleep_cancel() void TestTaskManager::sleep_task() { + QElapsedTimer timer; + qint64 elapsed; + // Set up the manager. TaskManager *manager = new TaskManager(); QSignalSpy sig_message(manager, SIGNAL(message(QString))); @@ -233,13 +237,18 @@ void TestTaskManager::sleep_task() // Set up a task and wait for it to start. manager->sleepSeconds(1, false); WAIT_SIG(sig_message); + timer.start(); QVERIFY(sig_message.takeFirst().at(0).toString() == "Started sleep task."); sig_message.clear(); // Wait for it to finish. WAIT_SIG(sig_message); + elapsed = timer.elapsed(); QVERIFY(sig_message.takeFirst().at(0).toString() == "Finished sleep task."); + // Check that it's been at least 900ms since the timer started. + QVERIFY(elapsed > 900); + // task is deleted by the task manager delete manager; }