Skip to content

Commit 71d3edb

Browse files
Ensure we do not connect to reapers created in test
1 parent 827d425 commit 71d3edb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/testcontainers/src/reaper/reaper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("Reaper", { timeout: 120_000 }, () => {
88

99
beforeEach(async () => {
1010
vi.resetModules();
11+
vi.stubEnv("TESTCONTAINERS_RYUK_TEST_LABEL", "true");
1112
client = await getContainerRuntimeClient();
1213
});
1314

packages/testcontainers/src/reaper/reaper.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export async function getReaper(client: ContainerRuntimeClient): Promise<Reaper>
4848
async function findReaperContainer(client: ContainerRuntimeClient): Promise<ContainerInfo | undefined> {
4949
const containers = await client.container.list();
5050
return containers.find(
51-
(container) => container.State === "running" && container.Labels[LABEL_TESTCONTAINERS_RYUK] === "true"
51+
(container) =>
52+
container.State === "running" &&
53+
container.Labels[LABEL_TESTCONTAINERS_RYUK] === "true" &&
54+
container.Labels["TESTCONTAINERS_RYUK_TEST_LABEL"] !== "true"
5255
);
5356
}
5457

@@ -81,9 +84,12 @@ async function createNewReaper(sessionId: string, remoteSocketPath: string): Pro
8184
if (process.env["TESTCONTAINERS_RYUK_VERBOSE"]) {
8285
container.withEnvironment({ RYUK_VERBOSE: process.env["TESTCONTAINERS_RYUK_VERBOSE"] });
8386
}
84-
if (process.env.TESTCONTAINERS_RYUK_PRIVILEGED === "true") {
87+
if (process.env["TESTCONTAINERS_RYUK_PRIVILEGED"] === "true") {
8588
container.withPrivilegedMode();
8689
}
90+
if (process.env["TESTCONTAINERS_RYUK_TEST_LABEL"] === "true") {
91+
container.withLabels({ TESTCONTAINERS_RYUK_TEST_LABEL: "true" });
92+
}
8793

8894
const startedContainer = await container.start();
8995

0 commit comments

Comments
 (0)