diff --git a/tests/test_game_gate.py b/tests/test_game_gate.py index 879419d5da..3356e4687f 100644 --- a/tests/test_game_gate.py +++ b/tests/test_game_gate.py @@ -194,6 +194,22 @@ def test_percentiles_come_from_the_presents(self): self.assertAlmostEqual(s["fps"]["end_median"], 25.0, delta=0.3) self.assertIsNone(s["fps"]["under_2_at_s"]) + def test_the_median_is_not_the_fastest_half(self): + # Every fixture in this file writes one frame rate, so median, mean and maximum were the same number and + # replacing statistics.median() with max() in parse_frames left all of them passing. This case has two + # halves: 40 fps and then 60, equal in length, so the median gap sits between the two and the a + # that gets read as a median is 48, while max() would answer 40 (1000 / the longest gap). + f = Fake() + f.event(1, "game", pid=1) + f.frames(70, 130, 50.0, 4000) # the world, first minute: not counted + f.frames(130, 190, 40.0, 4000) # counted: 60 s at 25 ms a frame, 2400 presents + f.frames(190, 230, 60.0, 4000) # counted: 40 s at 16.67 ms a frame, 2400 presents + f.clean_stop(430) + s = f.summarize() + self.assertAlmostEqual(s["fps"]["median"], 48.0, delta=1.0, + msg="the median of two equal halves is between them, not the slowest one") + # The two halves are visible in the other statistics too: the 5th percentile of fps is the slow half. + self.assertAlmostEqual(s["fps"]["p5"], 40.0, delta=1.0) def test_a_dip_on_arrival_is_not_the_first_second_under_2(self): # One frame a second just after the world (streaming in), then steady, then a dip later on: under_2_at_s # counts from 60 s in the world, like the median, and finds the later dip.