tests: make ViewerSmokeTimer.DifferentTimebases robust to CI jitter

The test assumed msleep(100) measures close to 100 ms (expecting ~2
frames at 24fps vs ~6 at 60fps). On the loaded macOS CI runner the
24fps leg overslept ~2.5x, producing 6 frames at both rates. Measure
the actual interval per leg and compare against the expected frame
count with a 1-frame tolerance, and use highly distinct timebases
(1fps vs 240fps) for the rate-ordering check.
This commit is contained in:
2026-07-17 22:08:03 +08:00
parent dff1f2955d
commit e18724129b
+21 -11
View File
@@ -95,20 +95,30 @@ TEST(ViewerSmokeTimer, PlaybackSpeedReverse)
TEST(ViewerSmokeTimer, DifferentTimebases)
{
ViewerPlaybackTimer timer;
// Frame counts track wall time at each timebase's rate. Measure the
// actual interval so scheduling jitter on loaded CI runners (observed on
// macOS, where msleep(100) overslept ~2.5x) can't break the comparison.
for (double fps : { 24.0, 60.0 }) {
ViewerPlaybackTimer timer;
QElapsedTimer wall;
timer.Start(0, 1, 1.0 / fps);
wall.start();
QThread::msleep(100);
// Test with 24fps
timer.Start(0, 1, 1.0 / 24.0);
const int64_t ts = timer.GetTimestampNow();
const int64_t expected =
qFloor(static_cast<double>(wall.elapsed()) / (1000.0 / fps));
EXPECT_NEAR(ts, expected, 1) << "fps=" << fps;
}
// With highly distinct timebases the faster one always produces more
// frames in the same interval, even on heavily loaded machines
ViewerPlaybackTimer slow, fast;
slow.Start(0, 1, 1.0);
fast.Start(0, 1, 1.0 / 240.0);
QThread::msleep(100);
int64_t ts24 = timer.GetTimestampNow();
// Test with 60fps
timer.Start(0, 1, 1.0 / 60.0);
QThread::msleep(100);
int64_t ts60 = timer.GetTimestampNow();
// At same real time, 60fps should have more frames than 24fps
EXPECT_GT(ts60, ts24);
EXPECT_LT(slow.GetTimestampNow(), fast.GetTimestampNow());
}
TEST(ViewerSmokeTimer, ZeroSpeed)