diff options
Diffstat (limited to 'packages/meshbay-node/tests/test_disk_io_off_loop.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_disk_io_off_loop.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/meshbay-node/tests/test_disk_io_off_loop.py b/packages/meshbay-node/tests/test_disk_io_off_loop.py index a94789a..44864ba 100644 --- a/packages/meshbay-node/tests/test_disk_io_off_loop.py +++ b/packages/meshbay-node/tests/test_disk_io_off_loop.py @@ -47,6 +47,11 @@ GROUP = "g" * 32 # gets ~40 wake-ups inside one of these and a blocked one gets none. SLOW_S = 0.2 TICK_S = 0.005 +# What a free loop actually achieves: Windows' asyncio timers run on the 15.6 ms +# system tick, so a 5 ms sleep takes 15.6 and a free loop gets ~13 wake-ups, +# never 40 -- every test here failed there against a threshold of 20. Still +# unmistakable: a blocked loop gets none. +FREE_TICKS = SLOW_S / max(TICK_S, time.get_clock_info("monotonic").resolution) CONTENT = b"a file worth waking a disk for" * 400 @@ -139,7 +144,7 @@ async def test_a_slow_chunk_read_does_not_stop_the_loop(tmp_path, monkeypatch): # The read really did take its time, and the loop really did keep running: # both halves matter, because a wrapper that never ran would also leave the # ticker free. - assert ticker.ticks > SLOW_S / TICK_S / 2, ( + assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s read") chunk = next(m for m in session.sent if m.get("type") == MNP.FILE_CHUNK) @@ -161,7 +166,7 @@ async def test_a_slow_stat_does_not_stop_the_loop(tmp_path, monkeypatch): await session._do_file_request( {"type": MNP.FILE_REQUEST, "file_id": entry.id, "chunk_index": 0}) - assert ticker.ticks > SLOW_S / TICK_S / 2, ( + assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s stat") assert any(m.get("type") == MNP.FILE_CHUNK for m in session.sent) @@ -230,7 +235,7 @@ async def test_the_availability_poll_does_not_stop_the_loop(tmp_path, monkeypatc await idx.stop() roots.close_io() - assert ticker.ticks > SLOW_S / TICK_S / 2, ( + assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s poll") @@ -322,7 +327,7 @@ async def test_a_slow_upload_write_does_not_stop_the_loop(tmp_path, monkeypatch) await session._do_file_upload(sealed_upload( session, filename="clip.bin", data=CONTENT)) - assert ticker.ticks > SLOW_S / TICK_S / 2, ( + assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s write") assert (shared / "clip.bin").read_bytes() == CONTENT @@ -405,5 +410,5 @@ async def test_a_slow_scratch_read_does_not_stop_the_loop(tmp_path, monkeypatch) media_tools._read_scratch_capped, scratch, 1 << 20, "subtitle track") assert blob == CONTENT - assert ticker.ticks > SLOW_S / TICK_S / 2, ( + assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s read") |