Ensure correct order when setting up fixtures

When setting up the global fixtures we need to ensure that the peers
that create changes sync their changes to the seed (palm). The only
thing necessary is for the peer to discover palm as the seed for the
project. Then `git push rad --all` will sync all changes to palm.

It’s not necessary to listen for any other event and we remove the
corresponding calls to `waitForEvent` or `waitForRoutes`.

In fact, these calls never did anything besides sleep since the
implementation of `waitForEvent` was faulty. We fix that, too.

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
Thomas Scholtes
2023-11-25 06:40:30 +01:00
committed by Sebastian Martinez
parent 456a4287fd
commit 999adff9c1
3 changed files with 32 additions and 55 deletions
+18 -22
View File
@@ -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();
}
+1 -1
View File
@@ -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),
});
+13 -32
View File
@@ -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");