Skip to content

Commit 9cbe3a4

Browse files
committed
fix(qa): drain Matrix decryptions before SDK shutdown
Punchcard-Session: silver-valley-valley-dt
1 parent cdffa8c commit 9cbe3a4

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client-internals.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export function createMatrixQaE2eeClientLifecycle(params: {
3939
drainPendingDecryptions: () => Promise<void>;
4040
shutdownTimeoutMs: number;
4141
stopAndPersist: () => Promise<void>;
42-
stopSyncWithoutPersist: () => void;
4342
stopWithoutPersist: () => void;
4443
}) {
4544
const activeOperations = new Set<Promise<unknown>>();
@@ -71,16 +70,15 @@ export function createMatrixQaE2eeClientLifecycle(params: {
7170
Promise.allSettled(activeOperations),
7271
graceMs,
7372
"active Matrix SDK operations did not settle before shutdown",
74-
).catch((error) => {
73+
).catch((error: unknown) => {
7574
failShutdown("waiting for active Matrix SDK operations", error);
7675
});
7776
}
78-
params.stopSyncWithoutPersist();
7977
await withMatrixQaE2eeTimeout(
8078
params.drainPendingDecryptions(),
8179
Math.max(0, deadline - Date.now()),
8280
"pending Matrix decryptions did not drain before shutdown",
83-
).catch((error) => {
81+
).catch((error: unknown) => {
8482
failShutdown("draining pending Matrix decryptions", error);
8583
});
8684
await params.stopAndPersist();

‎extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client.test.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,19 @@ describe("matrix qa e2ee client storage", () => {
3333
}),
3434
shutdownTimeoutMs: options?.shutdownTimeoutMs ?? 500,
3535
stopAndPersist: vi.fn(async () => {
36-
calls.push("persist");
36+
calls.push("stop-and-persist");
3737
}),
38-
stopSyncWithoutPersist: vi.fn(() => calls.push("stop-sync")),
39-
stopWithoutPersist: vi.fn(() => calls.push("discard")),
38+
stopWithoutPersist: vi.fn(() => calls.push("stop-and-discard")),
4039
});
4140
return { calls, lifecycle };
4241
}
4342

44-
it("stops sync, drains decryptions, and only then persists", async () => {
43+
it("drains decryptions before stopping the SDK and persisting", async () => {
4544
const { calls, lifecycle } = createLifecycleFixture();
4645

4746
await lifecycle.stop();
4847

49-
expect(calls).toEqual(["detach", "stop-sync", "drain", "persist"]);
48+
expect(calls).toEqual(["detach", "drain", "stop-and-persist"]);
5049
});
5150

5251
it("shares one stop promise across concurrent and repeated shutdown requests", async () => {
@@ -68,10 +67,10 @@ describe("matrix qa e2ee client storage", () => {
6867
}),
6968
).rejects.toThrow("shutdown has started");
7069
expect(run).not.toHaveBeenCalled();
71-
expect(calls).toEqual(["detach", "stop-sync", "drain", "persist"]);
70+
expect(calls).toEqual(["detach", "drain", "stop-and-persist"]);
7271
});
7372

74-
it("gives an active operation a bounded grace period before stopping sync", async () => {
73+
it("gives an active operation a bounded grace period before draining and stopping", async () => {
7574
vi.useFakeTimers();
7675
try {
7776
const { calls, lifecycle } = createLifecycleFixture();
@@ -92,7 +91,7 @@ describe("matrix qa e2ee client storage", () => {
9291
await operation;
9392
await stop;
9493

95-
expect(calls).toEqual(["operation", "detach", "stop-sync", "drain", "persist"]);
94+
expect(calls).toEqual(["operation", "detach", "drain", "stop-and-persist"]);
9695
} finally {
9796
vi.useRealTimers();
9897
}
@@ -120,7 +119,7 @@ describe("matrix qa e2ee client storage", () => {
120119
await vi.advanceTimersByTimeAsync(100);
121120

122121
await rejection;
123-
expect(calls).toEqual(["operation", "detach", "discard"]);
122+
expect(calls).toEqual(["operation", "detach", "stop-and-discard"]);
124123
} finally {
125124
vi.useRealTimers();
126125
}
@@ -144,7 +143,7 @@ describe("matrix qa e2ee client storage", () => {
144143
await vi.advanceTimersByTimeAsync(100);
145144

146145
await rejection;
147-
expect(calls).toEqual(["detach", "stop-sync", "drain", "discard"]);
146+
expect(calls).toEqual(["detach", "drain", "stop-and-discard"]);
148147
} finally {
149148
vi.useRealTimers();
150149
}
@@ -173,7 +172,7 @@ describe("matrix qa e2ee client storage", () => {
173172
await rejection;
174173
expect(calls).toEqual(["operation", "detach"]);
175174
await vi.advanceTimersByTimeAsync(100);
176-
expect(calls).toEqual(["operation", "detach", "discard"]);
175+
expect(calls).toEqual(["operation", "detach", "stop-and-discard"]);
177176
} finally {
178177
vi.useRealTimers();
179178
}

‎extensions/qa-lab/src/live-transports/matrix/substrate/e2ee-client.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ export async function createMatrixQaE2eeScenarioClient(
344344
drainPendingDecryptions: () => client.drainPendingDecryptions(),
345345
shutdownTimeoutMs,
346346
stopAndPersist: () => client.stopAndPersist(),
347-
stopSyncWithoutPersist: () => client.stopSyncWithoutPersist(),
348347
stopWithoutPersist: () => client.stopWithoutPersist(),
349348
});
350349

0 commit comments

Comments
 (0)