Skip to content

Commit b2cea9f

Browse files
committed
test: bound server creation and guarantee check termination
creating the dev server can hang before listen is ever called, and a hang there leaves live handles that keep the process alive even after the timeout error is reported; bound creation with the same timeout, exit hard once the final catch has reported (all cleanup has run by then), and stop a failing close from replacing the error that actually caused the failure. close() was still unbounded: it awaits plugin buildEnd and closeBundle hooks with no timeout of its own, so a hung close blocked the failure path's own exit, and on the success path could hang the process after the OK line had already printed. Bound every close() call the same way, and exit explicitly on both success and failure, since a leaked handle from any bounded step, close included, must not keep a finished check alive. (cherry picked from commit 62955d7)
1 parent 2111dd3 commit b2cea9f

2 files changed

Lines changed: 67 additions & 28 deletions

File tree

‎ui/scripts/check-locale-resolution.js‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ async function openProbe() {
9494
}
9595

9696
const { createServer, createServerModuleRunner } = await import('vite');
97-
const server = await createServer({
98-
root: UI_DIR,
99-
configFile: DEV_SERVER_CONFIG,
100-
logLevel: 'warn',
101-
});
97+
const server = await withTimeout(
98+
createServer({
99+
root: UI_DIR,
100+
configFile: DEV_SERVER_CONFIG,
101+
logLevel: 'warn',
102+
}),
103+
30000,
104+
'dev server creation did not complete within 30s',
105+
);
102106
try {
103107
await withTimeout(
104108
server.listen(),
@@ -110,7 +114,11 @@ async function openProbe() {
110114
// websocket server it created before listen() ever ran) already exists.
111115
// Nothing else will hold a reference to it once this throws, so close it
112116
// here or it keeps the event loop alive forever.
113-
await server.close().catch(() => {});
117+
await withTimeout(
118+
server.close(),
119+
10000,
120+
'dev server close did not complete within 10s',
121+
).catch(() => {});
114122
throw err;
115123
}
116124

@@ -182,7 +190,12 @@ async function openProbe() {
182190
}
183191
},
184192

185-
close: () => server.close(),
193+
close: () =>
194+
withTimeout(
195+
server.close(),
196+
10000,
197+
'dev server close did not complete within 10s',
198+
).catch(() => {}),
186199
};
187200
}
188201

@@ -232,11 +245,22 @@ async function main() {
232245
`resources, and ${TARGET_LANG} is fetchable over the dev server`,
233246
);
234247
} finally {
235-
await probe.close();
248+
await withTimeout(
249+
probe.close(),
250+
10000,
251+
'probe close did not complete within 10s',
252+
).catch(() => {});
236253
}
237254
}
238255

239-
main().catch((err) => {
240-
console.error(err.message || err.stack || String(err));
241-
process.exitCode = 1;
242-
});
256+
// Every finally above has already run by the time either callback below
257+
// fires, so a hard exit here cannot skip cleanup; it only guarantees
258+
// termination on both outcomes, including when a bounded-but-hung close
259+
// would otherwise keep a finished check alive after success.
260+
main().then(
261+
() => process.exit(0),
262+
(err) => {
263+
console.error(err.message || err.stack || String(err));
264+
process.exit(1);
265+
},
266+
);

‎ui/scripts/check-plugin-i18n-order.js‎

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,21 @@ async function main() {
7171
}
7272

7373
const { createServer, createServerModuleRunner } = await import('vite');
74-
const server = await createServer({
75-
root: UI_DIR,
76-
configFile: DEV_SERVER_CONFIG,
77-
logLevel: 'warn',
78-
// Without this the helper under test and this check each resolve their own
79-
// copy of i18next, and the check ends up inspecting an instance nobody
80-
// registered anything into. It reads as a failure with a confusing message
81-
// rather than as a broken harness, so the single-instance assertion below
82-
// guards it too.
83-
ssr: { noExternal: ['i18next'] },
84-
});
74+
const server = await withTimeout(
75+
createServer({
76+
root: UI_DIR,
77+
configFile: DEV_SERVER_CONFIG,
78+
logLevel: 'warn',
79+
// Without this the helper under test and this check each resolve
80+
// their own copy of i18next, and the check ends up inspecting an
81+
// instance nobody registered anything into. It reads as a failure
82+
// with a confusing message rather than as a broken harness, so the
83+
// single-instance assertion below guards it too.
84+
ssr: { noExternal: ['i18next'] },
85+
}),
86+
30000,
87+
'dev server creation did not complete within 30s',
88+
);
8589
try {
8690
await withTimeout(
8791
server.listen(),
@@ -196,11 +200,22 @@ async function main() {
196200
`after i18next.init (immediate) both survive and are present`,
197201
);
198202
} finally {
199-
await server.close();
203+
await withTimeout(
204+
server.close(),
205+
10000,
206+
'dev server close did not complete within 10s',
207+
).catch(() => {});
200208
}
201209
}
202210

203-
main().catch((err) => {
204-
console.error(err.message || err.stack || String(err));
205-
process.exitCode = 1;
206-
});
211+
// Every finally above has already run by the time either callback below
212+
// fires, so a hard exit here cannot skip cleanup; it only guarantees
213+
// termination on both outcomes, including when a bounded-but-hung close
214+
// would otherwise keep a finished check alive after success.
215+
main().then(
216+
() => process.exit(0),
217+
(err) => {
218+
console.error(err.message || err.stack || String(err));
219+
process.exit(1);
220+
},
221+
);

0 commit comments

Comments
 (0)