Skip to content

Commit 2e3c90c

Browse files
kriszypclaude
andcommitted
test: address Gemini review feedback for #1208 — closeAllConnections on teardown, consume fetch bodies
- Call server.closeAllConnections() before server.close() in MockOrigin.close() to drain keep-alive sockets immediately on teardown (Node ≥18.2, safe for engine ≥20). - Consume response bodies with .text() on the three fetch calls that only checked status (404 propagation test, DELETE test r1 and rDel) to avoid socket leaks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0ba407c commit 2e3c90c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

integrationTests/server/caching.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ async function startMockOrigin(): Promise<MockOrigin> {
6868

6969
return {
7070
url,
71-
close: () => new Promise<void>((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
71+
close: () => {
72+
server.closeAllConnections();
73+
return new Promise<void>((resolve, reject) => server.close((err) => (err ? reject(err) : resolve())));
74+
},
7275
fetchCount: (key) => fetchCounts.get(key) ?? 0,
7376
resetCounts: () => fetchCounts.clear(),
7477
setData: (key, value) => data.set(key, value),
@@ -250,6 +253,7 @@ suite('Caching: sourcedFrom and allowStaleWhileRevalidate', (ctx: any) => {
250253
const authHeader = `Basic ${Buffer.from(`${ctx.harper.admin.username}:${ctx.harper.admin.password}`).toString('base64')}`;
251254

252255
const r = await fetch(`${baseUrl}/CachedProduct/${id}`, { headers: { Authorization: authHeader } });
256+
await r.text();
253257
strictEqual(r.status, 404, 'Should return 404 when origin returns 404');
254258
strictEqual(origin.fetchCount(id), 1, 'Origin should have been called once');
255259
});
@@ -267,6 +271,7 @@ suite('Caching: sourcedFrom and allowStaleWhileRevalidate', (ctx: any) => {
267271

268272
// Populate cache
269273
const r1 = await fetch(`${baseUrl}/CachedProduct/${id}`, { headers: { Authorization: authHeader } });
274+
await r1.text();
270275
strictEqual(r1.status, 200);
271276
strictEqual(origin.fetchCount(id), 1, 'Should fetch from origin on first GET');
272277

@@ -275,6 +280,7 @@ suite('Caching: sourcedFrom and allowStaleWhileRevalidate', (ctx: any) => {
275280
method: 'DELETE',
276281
headers: { Authorization: authHeader },
277282
});
283+
await rDel.text();
278284
ok(rDel.status === 200 || rDel.status === 204, `DELETE should succeed, got ${rDel.status}`);
279285

280286
// Next GET must go back to the origin

0 commit comments

Comments
 (0)