Skip to content

Commit

Permalink
Speed up WGPS tests by tracking reconciliation status
Browse files Browse the repository at this point in the history
Currently the status will indicate done even when some entries are
yet to be processed, e.g. storing them. That's why there is still a
small(er) delay.
  • Loading branch information
xash committed Nov 21, 2024
1 parent 76488a8 commit c244d19
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/wgps/wgps_messenger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { emptyDir, ensureDir } from "@std/fs";
import { ANY_SUBSPACE, OPEN_END, type Range3d } from "@earthstar/willow-utils";
import { assert, assertEquals, assertNotEquals } from "@std/assert";
import { encodeBase64 } from "@std/encoding/base64";
import { WgpsStatusEvent } from "./events.ts";

type WgpsScenario = {
name: string;
Expand Down Expand Up @@ -1756,7 +1757,11 @@ function testWgpsMessenger(scenario: WgpsScenario) {
processReceivedPayload: (bytes) => bytes,
});

await delay(20 * scenario.timeMultiplier);
await Promise.all([
reconciliationDone(messengerAlfie),
reconciliationDone(messengerBetty),
]);
await delay(5 * scenario.timeMultiplier);

const range: Range3d<TestSubspace> = {
subspaceRange: {
Expand Down Expand Up @@ -2037,7 +2042,11 @@ function testWgpsMessenger(scenario: WgpsScenario) {
processReceivedPayload: (bytes) => bytes,
});

await delay(20 * scenario.timeMultiplier);
await Promise.all([
reconciliationDone(messengerAlfie),
reconciliationDone(messengerBetty),
]);
await delay(5 * scenario.timeMultiplier);

const range: Range3d<TestSubspace> = {
subspaceRange: {
Expand Down Expand Up @@ -2327,7 +2336,11 @@ function testWgpsMessenger(scenario: WgpsScenario) {
processReceivedPayload: (bytes) => bytes,
});

await delay(20 * scenario.timeMultiplier);
await Promise.all([
reconciliationDone(messengerAlfie),
reconciliationDone(messengerBetty),
]);
await delay(5 * scenario.timeMultiplier);

const range: Range3d<TestSubspace> = {
subspaceRange: {
Expand Down Expand Up @@ -2625,7 +2638,11 @@ function testWgpsMessenger(scenario: WgpsScenario) {
},
});

await delay(20 * scenario.timeMultiplier);
await Promise.all([
reconciliationDone(messengerAlfie),
reconciliationDone(messengerBetty),
]);
await delay(5 * scenario.timeMultiplier);

const range: Range3d<TestSubspace> = {
subspaceRange: {
Expand Down Expand Up @@ -2844,7 +2861,11 @@ function testWgpsMessenger(scenario: WgpsScenario) {
processReceivedPayload: (bytes) => bytes,
});

await delay(100 * scenario.timeMultiplier);
await Promise.all([
reconciliationDone(messengerAlfie),
reconciliationDone(messengerBetty),
]);
await delay(5 * scenario.timeMultiplier);

const range: Range3d<TestSubspace> = {
subspaceRange: {
Expand Down Expand Up @@ -3456,3 +3477,18 @@ export class StoreMap<
return newStore;
}
}

function reconciliationDone(wgps: any) {
return new Promise((resolve) => {
const status = wgps.status();
if (status.detail.todo === 0 && status.detail.all > 0) {
resolve(true);
} else {
wgps.addEventListener("status", (e: WgpsStatusEvent) => {
if (e.detail.todo === 0 && e.detail.all > 0) {
resolve(true);
}
});
}
});
}

0 comments on commit c244d19

Please sign in to comment.