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 | 43 |
1 files changed, 43 insertions, 0 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 44864ba..c0ab052 100644 --- a/packages/meshbay-node/tests/test_disk_io_off_loop.py +++ b/packages/meshbay-node/tests/test_disk_io_off_loop.py @@ -34,6 +34,7 @@ from meshbay_node.indexer.group_index import GroupIndex from meshbay_node.indexer.indexer import DirectoryIndexer from meshbay_node.roots import Root, RootSet from meshbay_node.transfers import LeaselessReads +from meshbay_node.transport import wire from meshbay_node.transport.webrtc import files, media_tools, upload_handlers from meshbay_node.transport.webrtc_server import WebRTCPeerSession from node_source import webrtc_files @@ -412,3 +413,45 @@ async def test_a_slow_scratch_read_does_not_stop_the_loop(tmp_path, monkeypatch) assert blob == CONTENT assert ticker.ticks > FREE_TICKS / 2, ( f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s read") + + +# ── The directory listing of a full index ─────────────────────────────────── +# +# Every `index_sync` lists the group's directories by walking all of its roots. +# On the loop, a library of several large roots was seconds in which the node +# answered nobody: found live, a tester adding a sixth directory lost "Add a +# directory" because the node missed the desktop client's 3 s check. + +async def test_a_slow_directory_walk_does_not_stop_the_loop(tmp_path, monkeypatch): + session, _, _, _ = await _served(tmp_path) + monkeypatch.setattr(wire, "_walk_dirs", _slow(wire._walk_dirs)) + + with _Ticker() as ticker: + await session._do_index_sync() + + assert ticker.ticks > FREE_TICKS / 2, ( + f"the loop was blocked: {ticker.ticks} wake-ups during a {SLOW_S}s walk") + assert session.sent[-1]["type"] == MNP.INDEX_SYNC + + +async def test_an_index_sync_that_fails_still_answers(tmp_path): + """It is spawned now, and a spawned task that fails only logs: without its + own answer the client would wait out its timeout for nothing.""" + session, ctx, _, _ = await _served(tmp_path) + del ctx["index"] + + await session._do_index_sync() + + assert session.sent[-1] == {"type": "error", "detail": "Request failed"} + + +def test_the_walk_lists_directories_and_skips_hidden_ones(tmp_path): + root = tmp_path / "films" + (root / "a" / "b").mkdir(parents=True) + (root / ".hidden" / "inside").mkdir(parents=True) + (root / "a" / "file.bin").write_bytes(b"x") + gone = tmp_path / "gone" + + dirs = wire._walk_dirs([("films", root, True), ("gone", gone, False)]) + + assert dirs == ["films", "films/a", "films/a/b", "gone"] |