From 4454d58695a39a94ca5f4ada982ebb3dd08519fd Mon Sep 17 00:00:00 2001 From: MattHandzel Date: Sun, 12 Oct 2025 15:43:55 -0500 Subject: [PATCH] Fix flaky container attach test by ensuring stream data is fully written The 'should receive container stdout on attach' test was intermittently failing because it didn't wait for stream data to be fully written before asserting. After containerWait() completes, explicitly wait for the stdout stream to finish by calling stream.end() and listening for the 'finish' event. This ensures all piped data has been written to the stdoutData array before assertions. Signed-off-by: MattHandzel --- test/container.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/container.test.ts b/test/container.test.ts index f3f5934..cfc6ab8 100644 --- a/test/container.test.ts +++ b/test/container.test.ts @@ -91,6 +91,22 @@ test('should receive container stdout on attach', async () => { // Wait for container to finish console.log(' Waiting for container to finish...'); const waitResult = await client.containerWait(containerId); + + // Wait for streams to finish writing all data + // This ensures all piped data has been written to our Writable streams + await new Promise((resolve) => { + // Set a timeout in case streams don't emit 'finish' event + const timeout = setTimeout(resolve, 1000); + + // Wait for stdout stream to finish + stdout.once('finish', () => { + clearTimeout(timeout); + resolve(); + }); + + // Trigger finish by ending the stream + stdout.end(); + }); console.log( ` Container finished with exit code: ${waitResult.StatusCode}`, );