Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Testcontainers.MongoDb/MongoDbBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ private static async Task InitiateReplicaSetAsync(MongoDbContainer container, Mo
return;
}

var readiness = new WaitIndicateReadiness(configuration);

// This is a simple workaround to use the default options, which can be configured
// with custom configurations as needed.
var options = new WaitStrategy();
Expand All @@ -212,6 +214,14 @@ private static async Task InitiateReplicaSetAsync(MongoDbContainer container, Mo
return 0L.Equals(execResult.ExitCode);
};

// The official MongoDB image starts mongod twice during the first-time
// initialization (bootstrap + final process). Waiting here prevents the
// replica set from being initiated while this handover is in progress,
// which could otherwise cause the container start to fail:
// https://github.com/testcontainers/testcontainers-dotnet/issues/1636.
await WaitStrategy.WaitUntilAsync(() => readiness.UntilAsync(container), options.Interval, options.Timeout, options.Retries, ct)
.ConfigureAwait(false);

await WaitStrategy.WaitUntilAsync(initiate, options.Interval, options.Timeout, options.Retries, ct)
.ConfigureAwait(false);
}
Expand Down
Loading