Skip to content

Commit 6ef4819

Browse files
committed
Add test for logs that is not sent in a single line
1 parent 843721e commit 6ef4819

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

packages/testcontainers/src/wait-strategies/log-wait-strategy.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,12 @@ describe("LogWaitStrategy", { timeout: 180_000 }, () => {
5656
});
5757

5858

59-
it("should throw an error if the message is never received", async () => {
60-
const containerName = `container-${new RandomUuid().nextUuid()}`;
61-
62-
await expect(
63-
new GenericContainer("cristianrgreco/testcontainer:1.1.14")
64-
.withName(containerName)
65-
.withCommand("/bin/sh", "-c", 'echo "Ready"')
66-
.withWaitStrategy(Wait.forLogMessage("unexpected"))
67-
.start()
68-
).rejects.toThrowError(`Log stream ended and message "unexpected" was not received`);
59+
it("does not matter if container does not send all content in a single line", async () => {
60+
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
61+
.withCommand(["node", "-e", "process.stdout.write('Hello '); setTimeout(() => process.stdout.write('World\\n'), 2000)"])
62+
.withWaitStrategy(Wait.forLogMessage("Hello World"))
63+
.start();
6964

70-
expect(await getRunningContainerNames()).not.toContain(containerName);
65+
await container.stop();
7166
});
72-
});
67+
});

packages/testcontainers/src/wait-strategies/log-wait-strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class LogWaitStrategy extends AbstractWaitStrategy {
3131

3232
let matches = 0;
3333
for await (const chunk of stream) {
34+
console.log(chunk)
3435
if (this.matches(chunk)) {
3536
if (++matches === this.times) {
3637
return log.debug(`Log wait strategy complete`, { containerId: container.id });

0 commit comments

Comments
 (0)