aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/tests/test_interactive.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-cli/tests/test_interactive.py')
-rw-r--r--packages/meshbay-cli/tests/test_interactive.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/meshbay-cli/tests/test_interactive.py b/packages/meshbay-cli/tests/test_interactive.py
index 36b7f47..9960533 100644
--- a/packages/meshbay-cli/tests/test_interactive.py
+++ b/packages/meshbay-cli/tests/test_interactive.py
@@ -444,3 +444,46 @@ async def test_put_sends_a_file_into_the_chat_folder_and_get_saves_one_here(
await say("/get ../share/x")
await _until(pilot, lambda: "name a file of the chat's folder" in _said(room))
await pilot.press("escape")
+
+
+async def test_index_updates_are_applied_not_asked_for_again(world, monkeypatch):
+ """
+ A library being enriched pushes an `index_delta` about once a second, each
+ one filling in a file's fields. The panes used to answer every one with the
+ whole index — 67 full indexes in the 80 s of one download on a real node,
+ on the event loop the download was being received on. Updates are applied
+ where they land; only a delta that adds or removes a file asks again, once
+ for a burst.
+ """
+ from meshbay_cli.tui import screens
+ monkeypatch.setattr(screens, "REFRESH_AFTER_DELTA_S", 0.2)
+ hub, node, work = world
+ film = node.add("share", "film.mkv", b"F" * 5000)
+ assert await asyncio.to_thread(cli.main, ["--hub", "https://hub.test", "-u", USERNAME,
+ "--password", PASSPHRASE, "login"]) == 0
+ app = _app()
+ async with app.run_test(size=(140, 40)) as pilot:
+ await _until(pilot, lambda: isinstance(app.screen, MainScreen))
+ remote = app.screen.query_one(RemotePane)
+ await _open(pilot, remote, f"Family@{USERNAME}/")
+ await _open(pilot, remote, "share/")
+ await _until(pilot, lambda: "film.mkv" in _names(remote))
+ asked = node.index_syncs
+
+ for i in range(20):
+ node.push_delta(updates=[{**film, "duration": 100 + i}])
+ await pilot.pause(0.6)
+ assert node.index_syncs == asked, "an update must not fetch the whole index"
+ tree = app.screen._trees["g1"]
+ assert tree.file("share/film.mkv")["duration"] == 119
+
+ extra = [node.add("share", f"new{i}.txt", b"n%d" % i) for i in range(3)]
+ node.files = {k: v for k, v in node.files.items() if v not in extra}
+ for e in extra:
+ node.push_delta(additions=[e])
+ await _until(pilot, lambda: "new2.txt" in _names(remote))
+ await pilot.pause(0.6)
+ assert node.index_syncs == asked + 1, "a burst of additions asks again once"
+
+ node.push_delta(deletions=[film["id"]])
+ await _until(pilot, lambda: "film.mkv" not in _names(remote))