aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests')
-rw-r--r--packages/meshbay-hub/tests/test_transfers.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/packages/meshbay-hub/tests/test_transfers.py b/packages/meshbay-hub/tests/test_transfers.py
index c7a9dc5..bacf5ac 100644
--- a/packages/meshbay-hub/tests/test_transfers.py
+++ b/packages/meshbay-hub/tests/test_transfers.py
@@ -582,8 +582,10 @@ const mkStore = () => {
state.starts.push(from);
state.running = true;
try {
- // Runs until told to stop, one "chunk" at a time.
+ // Runs until told to stop, one "chunk" at a time. `state.at` is how far
+ // it got, for a test to wait on instead of guessing a duration.
for (let i = from; i < 10; i++) {
+ state.at = i;
await new Promise(r => setTimeout(r, 5));
if (signal.aborted) { const e = new Error('c'); e.name = 'AbortError'; throw e; }
if (signal.paused) {
@@ -623,12 +625,21 @@ def test_pausing_gives_the_slot_back(tmp_path):
def test_resuming_asks_for_a_new_slot_and_continues_where_it_stopped(tmp_path):
"""Rejoining at the tail is the design, not an accident: a paused transfer
- that could reclaim its old place would be a way to hold one."""
+ that could reclaim its old place would be a way to hold one.
+
+ It waits for states, not durations: a `setTimeout(5)` lasts about 15 ms on
+ Windows' default timer, so the ten-chunk run outlived a fixed 120 ms wait
+ there (156 ms measured) and the test failed with nothing wrong."""
out = _run(_lease_stub() + _pausable_run() + """
+ const until = async (ok, ms = 2000) => {
+ for (const t0 = Date.now(); !ok() && Date.now() - t0 < ms;) {
+ await new Promise(r => setTimeout(r, 1));
+ }
+ };
const { t, leases, state } = mkStore();
await new Promise(r => setTimeout(r, 5));
leases[0].grant();
- await new Promise(r => setTimeout(r, 20));
+ await until(() => state.at >= 2);
const id = t.list()[0].id;
t.pause(id);
await new Promise(r => setTimeout(r, 30));
@@ -636,7 +647,7 @@ def test_resuming_asks_for_a_new_slot_and_continues_where_it_stopped(tmp_path):
await new Promise(r => setTimeout(r, 10));
say('queued:' + t.list()[0].status, 'leases:' + leases.length);
leases[1].grant();
- await new Promise(r => setTimeout(r, 120));
+ await until(() => t.list()[0].status === 'done');
say('end:' + t.list()[0].status);
say('starts:' + state.starts.join(','));
""", tmp_path)