summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_upload_seal_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests/test_upload_seal_client.py')
-rw-r--r--packages/meshbay-hub/tests/test_upload_seal_client.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/meshbay-hub/tests/test_upload_seal_client.py b/packages/meshbay-hub/tests/test_upload_seal_client.py
index d6f9156..2e4bfb5 100644
--- a/packages/meshbay-hub/tests/test_upload_seal_client.py
+++ b/packages/meshbay-hub/tests/test_upload_seal_client.py
@@ -167,3 +167,41 @@ def test_the_client_refuses_an_older_node_before_sending_a_chunk(_gek):
assert result["state"] == "rejected"
assert "older MeshBay" in result["message"]
assert result["frames"] == [], "a chunk was sent to a node that cannot open it"
+
+
+def test_an_interrupted_upload_resumes_where_the_node_stopped(tmp_path, _gek):
+ """
+ The browser asks, the node answers, and the second attempt sends only what
+ is missing.
+
+ Both halves are the shipped ones: the frames come from the real
+ `uploadFile`, the answer comes from the real node handler. What is asserted
+ is the thing that used to be impossible — an upload interrupted at chunk two
+ of five that sends three chunks instead of five.
+ """
+ body = bytes(range(256)) * ((CHUNK * 5) // 256 + 1)
+ body = body[:CHUNK * 5]
+ first = _run_probe(_probe_input(_gek, "send",
+ file={"name": "film.mkv", "data": body.hex()}))
+ frames = [msgpack.unpackb(bytes.fromhex(f), raw=False)
+ for f in first["frames"]]
+ assert [f["chunk_index"] for f in frames] == [-1, 0, 1, 2, 3, 4]
+
+ # The link drops after two chunks.
+ session = _node_session(tmp_path, _gek)
+ for frame in frames[1:3]:
+ session._do_file_upload(frame)
+ assert not [m for m in session.sent if m.get("type") == "error"]
+
+ # It comes back and asks.
+ session.sent.clear()
+ session._do_file_upload(frames[0])
+ probe_ack = msgpack.packb(session.sent[-1], use_bin_type=True).hex()
+
+ second = _run_probe(_probe_input(
+ _gek, "send", file={"name": "film.mkv", "data": body.hex()},
+ probe_ack=probe_ack))
+ resumed = [msgpack.unpackb(bytes.fromhex(f), raw=False)["chunk_index"]
+ for f in second["frames"]]
+ assert resumed == [-1, 2, 3, 4], (
+ f"sent {resumed} — the answer to the probe was not used")