Use a precise timer in QTestEventLoop if timeout is sub-second

QTestEventLoop is used by QSignalSpy::wait. If tests want to verify
that a signal gets emitted within a second or less, we should use
a precise timer to reduce the chance of timer imprecision breaking
the test.

Change-Id: I2a2ca3bbdcaf032288f1fdc2aecc6afd05a6c76c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Volker Hilsheimer 2022-05-06 11:43:18 +02:00
parent 5adaa8d868
commit fb8a88b05c
1 changed files with 2 additions and 1 deletions

View File

@ -64,7 +64,8 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
return;
QEventLoop l;
timerId = startTimer(ms);
// if tests want to measure sub-second precision, use a precise timer
timerId = startTimer(ms, ms < 1000 ? Qt::PreciseTimer : Qt::CoarseTimer);
loop = &l;
l.exec();