Skip to content

Commit 6c22505

Browse files
Merge remote-tracking branch 'origin/main' into codex/test-bun-compatibility
2 parents 0bffe60 + 99ff0a2 commit 6c22505

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

packages/testcontainers/src/container-runtime/clients/container/docker-container-client.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@ import { PassThrough, Readable } from "stream";
22
import { DockerContainerClient } from "./docker-container-client";
33

44
describe("DockerContainerClient", () => {
5+
describe("logs", () => {
6+
it("should destroy the Docker stream when the consumer closes the log stream", async () => {
7+
const actualLogStream = new PassThrough();
8+
const demuxStream = vi.fn();
9+
const container = {
10+
id: "container-id",
11+
logs: vi.fn(async () => actualLogStream),
12+
};
13+
const dockerode = {
14+
modem: { demuxStream },
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
} as any;
17+
const client = new DockerContainerClient(dockerode);
18+
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
const stream = await client.logs(container as any);
21+
await vi.waitFor(() => expect(demuxStream).toHaveBeenCalledOnce());
22+
stream.destroy();
23+
24+
await vi.waitFor(() => expect(actualLogStream.destroyed).toBe(true));
25+
});
26+
});
27+
528
describe("exec", () => {
629
it("should not truncate output when the demuxed streams flush after the raw stream ends", async () => {
730
const payload = "the-final-line-that-must-not-be-truncated\n";

packages/testcontainers/src/container-runtime/clients/container/docker-container-client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ export class DockerContainerClient implements ContainerClient {
194194
actualLogStream.socket?.unref();
195195

196196
const demuxedStream = await this.demuxStream(container.id, actualLogStream);
197+
if (proxyStream.destroyed) {
198+
demuxedStream.destroy();
199+
return;
200+
}
201+
proxyStream.once("close", () => demuxedStream.destroy());
197202
demuxedStream.pipe(proxyStream);
198203
demuxedStream.on("error", (err) => proxyStream.emit("error", err));
199204
demuxedStream.on("end", () => proxyStream.end());

0 commit comments

Comments
 (0)