diff options
Diffstat (limited to 'packages/meshbay-hub/tests/harness/search_connect_harness.mjs')
| -rw-r--r-- | packages/meshbay-hub/tests/harness/search_connect_harness.mjs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/packages/meshbay-hub/tests/harness/search_connect_harness.mjs b/packages/meshbay-hub/tests/harness/search_connect_harness.mjs index 60cea2ba..71c7e8c4 100644 --- a/packages/meshbay-hub/tests/harness/search_connect_harness.mjs +++ b/packages/meshbay-hub/tests/harness/search_connect_harness.mjs @@ -26,6 +26,11 @@ const { resolveAt = null, // How many nodes the hub lists for the group. nodes = 1, + // Which of them answer (resolveAt applies to these). null: all. + answering = null, + // Which of them this device refuses to reach on the local network: what the + // transport reads from its connection when search gives up on it. + lanRefused = [], // How far to run the clock before giving up on the harness itself. runUntil = 300000, } = cfg; @@ -65,13 +70,17 @@ async function run(until) { // ── The environment ────────────────────────────────────────────────────────── let closed = 0; +let made = 0; class FakeTransport { constructor() { this.onConnectProgress = null; this.onNeedToken = null; + this.index = made++; } + async localNetworkRefused() { return lanRefused.includes(this.index); } + connect() { const started = now; for (const at of progressAt) { @@ -84,7 +93,7 @@ class FakeTransport { }, at); } return new Promise((resolve) => { - if (resolveAt !== null) { + if (resolveAt !== null && (answering === null || answering.includes(this.index))) { setTimeout(() => resolve({ ok: true, at: now - started }), resolveAt); } }); @@ -127,7 +136,9 @@ const connectToGroup = make(hubFetch, ensureFreshToken, globalThis.window); let outcome = null; connectToGroup('https://hub.example', 'g1', 'tok', null, 'alice', 'u1') .then(() => { outcome = { result: 'connected', at: now }; }) - .catch((e) => { outcome = { result: 'failed', at: now, error: String(e.message) }; }); + .catch((e) => { + outcome = { result: 'failed', at: now, error: String(e.message), reason: e.reason || null }; + }); await run(runUntil); |