diff --git a/tests/support/fixtures.ts b/tests/support/fixtures.ts index 3e78c1ada..45fdb2e65 100644 --- a/tests/support/fixtures.ts +++ b/tests/support/fixtures.ts @@ -312,9 +312,7 @@ export async function createSourceBrowsingFixture( const bobProjectPath = Path.join(bob.checkoutPath, "source-browsing"); await alice.startNode({ connect: [palm.address], alias: "alice" }); await bob.startNode({ connect: [palm.address], alias: "bob" }); - await alice.waitForEvent({ type: "peerConnected", nid: palm.nodeId }, 1000); await palm.waitForEvent({ type: "peerConnected", nid: alice.nodeId }, 1000); - await bob.waitForEvent({ type: "peerConnected", nid: palm.nodeId }, 1000); await palm.waitForEvent({ type: "peerConnected", nid: bob.nodeId }, 1000); await alice.git(["clone", sourceBrowsingDir], { cwd: alice.checkoutPath }); @@ -337,22 +335,30 @@ export async function createSourceBrowsingFixture( ], { cwd: aliceProjectPath }, ); + await alice.waitForEvent( + { + type: "seedDiscovered", + rid, + nid: palm.nodeId, + }, + 2000, + ); + // Needed due to rad init not pushing all branches. await alice.git(["push", "rad", "--all"], { cwd: aliceProjectPath }); - await alice.rad(["track", bob.nodeId, "--alias", "bob"], { - cwd: aliceProjectPath, - }); + await alice.stopNode(); - await alice.waitForRoutes(rid, alice.nodeId, palm.nodeId); - await bob.waitForRoutes(rid, alice.nodeId, palm.nodeId); - await palm.waitForRoutes(rid, alice.nodeId, palm.nodeId); + await bob.waitForEvent( + { + type: "seedDiscovered", + rid, + nid: palm.nodeId, + }, + 2000, + ); await bob.rad(["clone", rid], { cwd: bob.checkoutPath }); - await alice.waitForRoutes(rid, alice.nodeId, palm.nodeId, bob.nodeId); - await bob.waitForRoutes(rid, alice.nodeId, palm.nodeId, bob.nodeId); - await palm.waitForRoutes(rid, alice.nodeId, palm.nodeId, bob.nodeId); - await Fs.writeFile( Path.join(bob.checkoutPath, "source-browsing", "README.md"), "Updated readme", @@ -369,16 +375,6 @@ export async function createSourceBrowsingFixture( { cwd: bobProjectPath }, ); await bob.git(["push", "rad"], { cwd: bobProjectPath }); - - await bob.waitForEvent( - { type: "refsSynced", remote: palm.nodeId, rid }, - 2000, - ); - await bob.waitForEvent( - { type: "refsSynced", remote: alice.nodeId, rid }, - 2000, - ); - await alice.stopNode(); await bob.stopNode(); } diff --git a/tests/support/globalSetup.ts b/tests/support/globalSetup.ts index 911cc60f7..2456fe26a 100644 --- a/tests/support/globalSetup.ts +++ b/tests/support/globalSetup.ts @@ -38,7 +38,7 @@ export default async function globalSetup(): Promise<() => void> { const peerManager = await createPeerManager({ dataDir: Path.resolve(Path.join(tmpDir, "peers")), outputLog: FsSync.createWriteStream( - Path.join(tmpDir, "peerManager.log"), + Path.join(tmpDir, "globalSetup.log"), ).setMaxListeners(16), }); diff --git a/tests/support/peerManager.ts b/tests/support/peerManager.ts index 1563a7458..f0fe02bae 100644 --- a/tests/support/peerManager.ts +++ b/tests/support/peerManager.ts @@ -187,8 +187,19 @@ export class RadiclePeer { public async waitForEvent(searchEvent: NodeEvent, timeoutInMs: number) { const start = new Date().getTime(); - while (new Date().getTime() - start > timeoutInMs) { - this.#eventRecords.find(event => lodash.isEqual(searchEvent, event)); + // eslint-disable-next-line no-constant-condition + while (true) { + if (this.#eventRecords.find(lodash.matches(searchEvent))) { + return; + } + if (new Date().getTime() - start > timeoutInMs) { + throw Error( + `Timeout waiting for event on node ${this.#name} ${Util.inspect( + searchEvent, + { depth: null }, + )}`, + ); + } await sleep(100); } } @@ -341,36 +352,6 @@ export class RadiclePeer { }); } - public async waitForRoutes(rid: string, ...nodes: string[]) { - let remaining = nodes; - - while (remaining.length > 0) { - const { stdout: entries } = await this.rad( - ["node", "routing", "--rid", rid, "--json"], - { logPrefix: null }, - ); - - if (!entries) { - throw new Error("No entries found in the routing table"); - } - entries.split("\n").forEach(entry => { - if (entry && entry.trim() !== "") { - try { - const result: RoutingEntry = JSON.parse(entry); - remaining = remaining.filter(nid => result.nid !== nid); - } catch (e) { - console.log("Error parsing entry", entry); - } - } - }); - - await this.waitForEvent( - { type: "seedDiscovered", rid, nid: this.nodeId }, - 6000, - ); - } - } - public get address(): string { if (!this.#listenSocketAddr) { throw new Error("Remote node has no listen addr yet");