Skip to content

Commit 3a2c41b

Browse files
committed
test: release every gated response on teardown
A gate the test never releases, because an assertion failed before it got there, leaves its route awaiting forever. Gates now register themselves and an afterEach hook drains them, so this cannot be reintroduced by a future test that forgets. The reported hang does not reproduce: closing the browser destroys the client socket, so the suspended route holds no live handle and the runner exits. Forcing the assertion to fail reported the failure and exited in seven seconds. The cleanup is worth having regardless.
1 parent 569692c commit 3a2c41b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

test/browser/reconnect.test.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "node:assert/strict"
2-
import { test, before, after, beforeEach } from "node:test"
2+
import { test, before, after, beforeEach, afterEach } from "node:test"
33
import { startServer, openPage, loadPage, frameHtml } from "./browser_test_helper.mjs"
44

55
// A reconnecting subscription replays the current state as a burst of refresh
@@ -14,6 +14,11 @@ let page
1414
const batches = new Map()
1515
const components = new Map()
1616
const cancelled = new Set()
17+
const gates = []
18+
19+
function releaseGates() {
20+
while (gates.length) gates.pop()()
21+
}
1722

1823
before(async () => {
1924
const started = await startServer({
@@ -47,10 +52,15 @@ before(async () => {
4752
})
4853

4954
after(async () => {
55+
releaseGates()
5056
await browser?.close()
5157
server?.close()
5258
})
5359

60+
afterEach(() => {
61+
releaseGates()
62+
})
63+
5464
beforeEach(async () => {
5565
batches.clear()
5666
components.clear()
@@ -67,11 +77,15 @@ async function waitFor(condition, message) {
6777
assert.fail(message)
6878
}
6979

80+
// A gate a test forgets to release, because an assertion failed before it got
81+
// there, leaves its route awaiting forever and turns a reported failure into a
82+
// hung suite. Every gate is released when the test that made it finishes.
7083
function gate() {
7184
let release
7285
const promise = new Promise((resolve) => {
7386
release = resolve
7487
})
88+
gates.push(release)
7589
return { promise, release }
7690
}
7791

0 commit comments

Comments
 (0)