Skip to content

Commit cd717aa

Browse files
committed
fix tests in podman
1 parent 7f47bef commit cd717aa

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

packages/modules/mongodb/src/mongodb-container.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("MongodbContainer", { timeout: 240_000 }, () => {
6767
});
6868

6969
describe("MongodbContainer connect with credentials", { timeout: 240_000 }, () => {
70-
it.for([["mongo:4.0.1"], ["mongo:5.0"], ["mongo:8.0"]])("should connect to %s with credentials", async ([image]) => {
70+
it.for([["mongo:4.0.1"], ["mongo:8.0"]])("should connect to %s with credentials", async ([image]) => {
7171
const mongodbContainer = await new MongoDBContainer(image)
7272
.withUsername("mongo_user")
7373
.withPassword("mongo_password")

packages/modules/mongodb/src/mongodb-container.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ export class MongoDBContainer extends GenericContainer {
2727
public override async start(): Promise<StartedMongoDBContainer> {
2828
const cmdArgs = ["--replSet", "rs0", "--bind_ip_all"];
2929
this.withHealthCheck({
30-
test: ["CMD", ...this.buildMongoEvalCommand(this.buildMongoWaitCommand())],
31-
startPeriod: 1_000,
32-
timeout: 60_000,
33-
retries: 10,
34-
interval: 2_000,
30+
test: ["CMD-SHELL", this.buildMongoEvalCommand(this.initRsAndWait())],
31+
interval: 250,
32+
timeout: 60000,
33+
retries: 1000,
3534
}).withWaitStrategy(Wait.forHealthCheck());
36-
if (this.authEnabled()) {
35+
if (this.username && this.password) {
3736
cmdArgs.push("--keyFile", "/data/db/key.txt");
3837
this.withEnvironment({
3938
MONGO_INITDB_ROOT_USERNAME: this.username,
@@ -58,16 +57,13 @@ export class MongoDBContainer extends GenericContainer {
5857
const args = [];
5958
if (useMongosh) args.push("mongosh");
6059
else args.push("mongo", "admin");
61-
args.push("-u", this.username, "-p", this.password, "--eval", command);
62-
return args;
60+
if (this.username && this.password) args.push("-u", this.username, "-p", this.password);
61+
args.push("--host", "localhost", "--quiet", "--eval", command);
62+
return args.join(" ");
6363
}
6464

65-
private buildMongoWaitCommand() {
66-
return `rs.initiate(); while (db.runCommand({isMaster: 1}).ismaster==false) { sleep(1000); } `;
67-
}
68-
69-
private authEnabled() {
70-
return this.username && this.password;
65+
private initRsAndWait() {
66+
return `'try { rs.initiate(); } catch (e){} while (db.runCommand({isMaster: 1}).ismaster==false) { sleep(100); }'`;
7167
}
7268
}
7369

0 commit comments

Comments
 (0)