From b6d5d7373fbf8faaee18fba613bd8bf570bce80d Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Fri, 20 Nov 2026 03:39:06 +0400 Subject: [PATCH] Check that the Tarktee body-failure tests close the sibling request --- src/data/cctvEstoniaBodyPhase.test.mjs | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/data/cctvEstoniaBodyPhase.test.mjs b/src/data/cctvEstoniaBodyPhase.test.mjs index 92c3c80d8a..dfc4782e2a 100644 --- a/src/data/cctvEstoniaBodyPhase.test.mjs +++ b/src/data/cctvEstoniaBodyPhase.test.mjs @@ -37,13 +37,26 @@ function routeFetchTo(t, port) { }); } -const slowHeaders = (req, res) => { - const timer = setTimeout(() => { - res.writeHead(200, { 'content-type': 'application/xml' }); - res.end(''); - }, SIBLING_HEADER_DELAY_MS); - res.on('close', () => clearTimeout(timer)); -}; +/** The sibling answers late and reports whether it was cut off before headers. */ +function slowSibling() { + const arrived = Promise.withResolvers(); + const closed = Promise.withResolvers(); + return { + arrived: arrived.promise, + closed: closed.promise, + handler(req, res) { + arrived.resolve(); + const timer = setTimeout(() => { + res.writeHead(200, { 'content-type': 'application/xml' }); + res.end(''); + }, SIBLING_HEADER_DELAY_MS); + res.on('close', () => { + clearTimeout(timer); + closed.resolve({ beforeHeaders: !res.headersSent }); + }); + }, + }; +} const failingBodies = { 'declares a body over the byte cap': (req, res) => { @@ -68,9 +81,11 @@ for (const [label, failingFeed] of Object.entries(failingBodies)) { test(`Tarktee aborts ${pending} pending headers when ${failing} ${label}`, { timeout: 10_000 }, async (t) => { t.mock.method(console, 'log', () => {}); t.mock.method(console, 'warn', () => {}); + const sibling = slowSibling(); const server = await startServer({ - [failing]: failingFeed, - [pending]: slowHeaders, + [failing]: (req, res) => + sibling.arrived.then(() => failingFeed(req, res)), + [pending]: sibling.handler, }); t.after(() => { server.closeAllConnections(); @@ -87,6 +102,11 @@ for (const [label, failingFeed] of Object.entries(failingBodies)) { elapsed < FAIL_FAST_MS, `loader waited ${elapsed} ms for the sibling's headers instead of aborting it`, ); + assert.deepEqual( + await sibling.closed, + { beforeHeaders: true }, + `${pending} was not aborted`, + ); }); } }