Skip to content

Commit 82e299c

Browse files
committed
Wrap runtime-singletons test with harness isolation
1 parent 5e3e731 commit 82e299c

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

tests/unit/runtime-singletons.test.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,29 @@ test("createTestHarness swaps singleton state atomically and restores it on tear
2222
});
2323

2424
test("__setSingletons warns when preserving in-flight write lock", () => {
25-
const warnings: string[] = [];
26-
const originalWarn = console.warn;
27-
console.warn = (msg: string) => {
28-
warnings.push(msg);
29-
};
25+
// Use harness to isolate the test's singleton manipulation
26+
const h = createTestHarness();
3027
try {
31-
const s = getSingletons();
32-
s.writeLock.pending = 1; // simulate in-flight write
33-
__setSingletons({
34-
writeLock: createWriteLock(),
35-
writeContext: new AsyncLocalStorage<true>(),
36-
frameScheduler: s.frameScheduler,
37-
});
38-
assert.ok(warnings.length > 0);
39-
assert.match(warnings[0], /pending/);
28+
const warnings: string[] = [];
29+
const originalWarn = console.warn;
30+
console.warn = (msg: string) => {
31+
warnings.push(msg);
32+
};
33+
try {
34+
const s = getSingletons();
35+
s.writeLock.pending = 1; // simulate in-flight write on test singleton
36+
__setSingletons({
37+
writeLock: createWriteLock(),
38+
writeContext: new AsyncLocalStorage<true>(),
39+
frameScheduler: s.frameScheduler,
40+
});
41+
assert.ok(warnings.length > 0);
42+
assert.match(warnings[0], /pending/);
43+
} finally {
44+
console.warn = originalWarn;
45+
}
4046
} finally {
41-
getSingletons().writeLock.pending = 0; // clean up
42-
__setSingletons(getSingletons(), { forceWriteLock: true }); // restore clean state
43-
console.warn = originalWarn;
47+
h.teardown();
4448
}
4549
});
4650

0 commit comments

Comments
 (0)