"""Publisher must not catch up frames and must recycle native encoders on RSS.""" from latency import ( next_video_capture, should_recycle_encoders, ) def test_next_video_capture_sleeps_until_due(): capture, due = next_video_capture(now=10.0, due=10.05, period=1 / 30) assert capture is False assert due == 10.05 def test_next_video_capture_fires_on_due_and_advances_one_period(): capture, due = next_video_capture(now=10.0, due=10.0, period=0.05) assert capture is True assert due == 10.05 def test_next_video_capture_skips_catchup_when_behind(): # 80 ms late at 30 fps would be two extra ticks if we kept adding period. capture, due = next_video_capture(now=10.08, due=10.0, period=1 / 30) assert capture is True assert due == 10.08 + (1 / 30) def test_should_recycle_when_anon_rss_exceeds_limit_and_interval_elapsed(): assert should_recycle_encoders( rss_anon_kb=4_000_000, limit_kb=3_000_000, now=100.0, last_recycle_at=0.0, min_interval_s=60.0, ) is True def test_should_not_recycle_below_limit(): assert should_recycle_encoders( rss_anon_kb=1_000_000, limit_kb=3_000_000, now=100.0, last_recycle_at=0.0, min_interval_s=60.0, ) is False def test_should_not_recycle_inside_min_interval(): assert should_recycle_encoders( rss_anon_kb=5_000_000, limit_kb=3_000_000, now=100.0, last_recycle_at=80.0, min_interval_s=60.0, ) is False def test_should_not_recycle_when_limit_disabled(): assert should_recycle_encoders( rss_anon_kb=9_000_000, limit_kb=0, now=100.0, last_recycle_at=0.0, min_interval_s=60.0, ) is False