Skip to content

Commit

Permalink
tests/taskmanager: check that sleepSeconds() actually waits
Browse files Browse the repository at this point in the history
  • Loading branch information
gperciva committed Dec 7, 2023
1 parent 96d05e9 commit f8c6bfc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/taskmanager/test-taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ WARNINGS_DISABLE
#include <QChar>
#include <QCoreApplication>
#include <QDir>
#include <QElapsedTimer>
#include <QFile>
#include <QIODevice>
#include <QList>
Expand Down Expand Up @@ -226,20 +227,28 @@ 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)));

// 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;
}
Expand Down

0 comments on commit f8c6bfc

Please sign in to comment.