Skip to content

Commit 454f371

Browse files
committed
test(qa): assert Matrix proxy cleanup by owner
1 parent b5038f7 commit 454f371

2 files changed

Lines changed: 11 additions & 23 deletions

File tree

‎extensions/qa-lab/src/live-transports/matrix/scenarios/scenario-runtime-e2ee-cli-account.test.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { startMatrixQaFaultProxy } from "../substrate/fault-proxy.js";
88
import type { MatrixQaCliSession } from "./scenario-runtime-cli.js";
99
import { runMatrixQaE2eeCliEncryptionSetupBootstrapFailureScenario } from "./scenario-runtime-e2ee-cli-account.js";
1010
import { MATRIX_QA_ROOM_KEY_BACKUP_VERSION_ENDPOINT } from "./scenario-runtime-e2ee-shared.js";
11-
import {
12-
assertMatrixQaTestPortClosed,
13-
createMatrixQaE2eeTestContext,
14-
} from "./scenario-runtime-e2ee.test-helpers.js";
11+
import { createMatrixQaE2eeTestContext } from "./scenario-runtime-e2ee.test-helpers.js";
1512

1613
const mocks = vi.hoisted(() => ({ createRuntime: vi.fn() }));
1714
vi.mock("./scenario-runtime-e2ee-cli-runtime.js", () => ({
@@ -65,6 +62,8 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
6562
stop: async () => {
6663
await beforeProxyStop?.();
6764
stopping = proxy.stop().then(() => {
65+
// The real stop joins this server's close event. Its released port may
66+
// already belong to another worker when the scenario settles.
6867
closed = true;
6968
});
7069
await stopping;
@@ -128,7 +127,7 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
128127
async ({ methods }) => {
129128
configureCli(methods);
130129
await expect(run()).rejects.toThrow("did not attempt faulted room-key backup creation");
131-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
130+
expect(closed).toBe(true);
132131
expect(dispose).toHaveBeenCalledOnce();
133132
},
134133
);
@@ -138,19 +137,19 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
138137
await expect(run()).resolves.toMatchObject({
139138
artifacts: { bootstrapSuccess: false, faultHitCount: 2 },
140139
});
141-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
140+
expect(closed).toBe(true);
142141
closed = false;
143142
configureCli(["POST"], "unrelated failure");
144143
await expect(run()).rejects.toThrow("unexpected reason");
145-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
144+
expect(closed).toBe(true);
146145
});
147146

148147
it.each([new Error("runtime construction failed"), undefined, "construction rejected"])(
149148
"closes the already-acquired proxy and preserves construction rejection %s",
150149
async (failure) => {
151150
mocks.createRuntime.mockRejectedValueOnce(failure);
152151
await expect(run()).rejects.toBe(failure);
153-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
152+
expect(closed).toBe(true);
154153
},
155154
);
156155

@@ -163,7 +162,7 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
163162
cause: failure,
164163
errors: [failure, proxyCleanupFailure],
165164
});
166-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
165+
expect(closed).toBe(true);
167166
},
168167
);
169168

@@ -173,7 +172,7 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
173172
configureCli(["POST"]);
174173
dispose.mockRejectedValueOnce(failure);
175174
await expect(run()).rejects.toBe(failure);
176-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
175+
expect(closed).toBe(true);
177176
},
178177
);
179178

@@ -186,7 +185,7 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
186185
cause: disposalFailure,
187186
errors: [disposalFailure, proxyCleanupFailure],
188187
});
189-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
188+
expect(closed).toBe(true);
190189
});
191190

192191
it("joins proxy cleanup before returning a CLI disposal failure", async () => {
@@ -212,6 +211,6 @@ describe("Matrix CLI bootstrap failure evidence and ownership", () => {
212211
release.resolve();
213212
expect(await operation).toBe(disposalFailure);
214213
}
215-
await assertMatrixQaTestPortClosed(proxy.baseUrl);
214+
expect(closed).toBe(true);
216215
});
217216
});

‎extensions/qa-lab/src/live-transports/matrix/scenarios/scenario-runtime-e2ee.test-helpers.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createServer } from "node:net";
21
import type { MatrixVerificationBootstrapResult } from "@openclaw/matrix/test-api.js";
32
import type { MatrixQaScenarioContext } from "./scenario-runtime-shared.js";
43

@@ -24,16 +23,6 @@ export function createMatrixQaE2eeTestContext(
2423
};
2524
}
2625

27-
export async function assertMatrixQaTestPortClosed(baseUrl: string) {
28-
const probe = createServer();
29-
await new Promise<void>((resolve, reject) => {
30-
probe.once("error", reject);
31-
probe.listen(Number(new URL(baseUrl).port), "127.0.0.1", () => {
32-
probe.close((error) => (error ? reject(error) : resolve()));
33-
});
34-
});
35-
}
36-
3726
export function createMatrixQaBootstrapFailure(): MatrixVerificationBootstrapResult {
3827
return {
3928
success: false,

0 commit comments

Comments
 (0)