test(sandbox): stabilize duplicate registration test
This commit is contained in:
parent
af1bc0e666
commit
4cfceecb9a
@ -10,22 +10,28 @@ test("duplicate traposId is resolved newest-wins", async () => {
|
|||||||
const sandbox = await startSandbox();
|
const sandbox = await startSandbox();
|
||||||
const TRAPOS_ID = "9:dup";
|
const TRAPOS_ID = "9:dup";
|
||||||
|
|
||||||
|
// Newest-wins is decided by the order hello frames reach the gateway, which is
|
||||||
|
// independent of the client-side READY print order. Spawn the two computers
|
||||||
|
// sequentially — only start `second` once `first` is registered server-side —
|
||||||
|
// so `second` is unambiguously the newer registration.
|
||||||
const first = startCraftos("gateway-client.lua", {
|
const first = startCraftos("gateway-client.lua", {
|
||||||
computerId: 9,
|
computerId: 9,
|
||||||
computerLabel: "dup",
|
computerLabel: "dup",
|
||||||
shellArgs: [sandbox.baseUrl, "-", "idle", "60"],
|
shellArgs: [sandbox.baseUrl, "-", "idle", "60"],
|
||||||
});
|
});
|
||||||
const second = startCraftos("gateway-client.lua", {
|
|
||||||
computerId: 9,
|
|
||||||
computerLabel: "dup",
|
|
||||||
shellArgs: [sandbox.baseUrl, "-", "idle"],
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let second: ReturnType<typeof startCraftos> | undefined;
|
||||||
try {
|
try {
|
||||||
await waitFor(() => first.snapshot().includes("__SANDBOX_READY__"), 12_000, "first connected");
|
await waitFor(() => first.snapshot().includes("__SANDBOX_READY__"), 12_000, "first connected");
|
||||||
assert.ok(sandbox.registry.has("local", TRAPOS_ID), "first should be registered");
|
await waitFor(() => sandbox.registry.has("local", TRAPOS_ID), 2_000, "first registered server-side");
|
||||||
|
|
||||||
await waitFor(() => second.snapshot().includes("__SANDBOX_READY__"), 12_000, "second connected");
|
const secondHandle = startCraftos("gateway-client.lua", {
|
||||||
|
computerId: 9,
|
||||||
|
computerLabel: "dup",
|
||||||
|
shellArgs: [sandbox.baseUrl, "-", "idle"],
|
||||||
|
});
|
||||||
|
second = secondHandle;
|
||||||
|
await waitFor(() => secondHandle.snapshot().includes("__SANDBOX_READY__"), 12_000, "second connected");
|
||||||
// Newest-wins: still exactly one registration for the shared id.
|
// Newest-wins: still exactly one registration for the shared id.
|
||||||
assert.equal(sandbox.registry.count(), 1, "exactly one registration after the duplicate");
|
assert.equal(sandbox.registry.count(), 1, "exactly one registration after the duplicate");
|
||||||
assert.ok(sandbox.registry.has("local", TRAPOS_ID));
|
assert.ok(sandbox.registry.has("local", TRAPOS_ID));
|
||||||
@ -38,14 +44,14 @@ test("duplicate traposId is resolved newest-wins", async () => {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
formatFailure(
|
formatFailure(
|
||||||
error instanceof Error ? error.message : String(error),
|
error instanceof Error ? error.message : String(error),
|
||||||
`first:\n${first.snapshot()}\nsecond:\n${second.snapshot()}`,
|
`first:\n${first.snapshot()}\nsecond:\n${second?.snapshot() ?? "(not started)"}`,
|
||||||
),
|
),
|
||||||
{ cause: error },
|
{ cause: error },
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
first.abort();
|
first.abort();
|
||||||
second.abort();
|
second?.abort();
|
||||||
await Promise.all([first.done.catch(() => undefined), second.done.catch(() => undefined)]);
|
await Promise.all([first.done.catch(() => undefined), second?.done.catch(() => undefined)]);
|
||||||
await sandbox.close();
|
await sandbox.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user