Skip to content

Commit

Permalink
QTest::qWaitFor: move ceil<> to after the check
Browse files Browse the repository at this point in the history
There's no reason to check whether the timer has expired after
rounding the timer's native nanoseconds up to milliseconds, so delay
the ceil<ms> operation to after the timer expiry check.

As a drive-by, protect the std::min call from Windows macros with the
parentheses trick and employ C++17 if-with-initializer.

Remove the break-if-expired, as it now obviously duplicates the while
exit condition.

Pick-to: 6.7
Change-Id: If30421012143640c75a9a44fe711d0c1c7cd23b9
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
marcmutz committed Mar 15, 2024
1 parent ad2da20 commit 5954965
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/corelib/kernel/qtestsupport_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ qWaitFor(Functor predicate, QDeadlineTimer deadline = QDeadlineTimer(std::chrono
if (predicate())
return true;

const auto remaining = ceil<milliseconds>(deadline.remainingTimeAsDuration());
if (remaining == 0ms)
break;
if (const auto remaining = deadline.remainingTimeAsDuration(); remaining > 0ns)
qSleep((std::min)(10ms, ceil<milliseconds>(remaining)));

qSleep(std::min(10ms, remaining));
} while (!deadline.hasExpired());

return predicate(); // Last chance
Expand Down

0 comments on commit 5954965

Please sign in to comment.