Skip to content

Commit

Permalink
fix(MongoDb): Evaluate replica set status in wait strategy (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Feb 13, 2025
1 parent b93162c commit 13dcbe4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="12.2.8"/>
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2"/>
<PackageVersion Include="Milvus.Client" Version="2.2.2-preview.6"/>
<PackageVersion Include="MongoDB.Driver" Version="2.19.0"/>
<PackageVersion Include="MongoDB.Driver" Version="3.2.0"/>
<PackageVersion Include="MyCouch" Version="7.6.0"/>
<PackageVersion Include="MySqlConnector" Version="2.2.5"/>
<PackageVersion Include="NATS.Client" Version="1.0.8"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.MongoDb/MongoDbBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private sealed class WaitInitiateReplicaSet : IWaitUntil
/// <param name="configuration">The container configuration.</param>
public WaitInitiateReplicaSet(MongoDbConfiguration configuration)
{
_scriptContent = $"try{{rs.status().ok}}catch(e){{rs.initiate({{'_id':'{configuration.ReplicaSetName}',members:[{{'_id':1,'host':'127.0.0.1:27017'}}]}}).ok}}";
_scriptContent = $"try{{rs.status()}}catch(e){{rs.initiate({{_id:'{configuration.ReplicaSetName}',members:[{{_id:0,host:'127.0.0.1:27017'}}]}});throw e;}}";
}

/// <inheritdoc />
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.MongoDb/MongoDbContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public string GetConnectionString()
var endpoint = new UriBuilder("mongodb", Hostname, GetMappedPublicPort(MongoDbBuilder.MongoDbPort));
endpoint.UserName = Uri.EscapeDataString(_configuration.Username);
endpoint.Password = Uri.EscapeDataString(_configuration.Password);
endpoint.Query = "?directConnection=true";
return endpoint.ToString();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Testcontainers.MongoDb.Tests/MongoDbContainerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task ReplicaSetStatus()
}
else
{
Assert.Equal(1L, execResult.ExitCode);
Assert.True(1L.Equals(execResult.ExitCode), execResult.Stdout);
Assert.Equal("MongoServerError: not running with --replSet\n", execResult.Stderr);
}
}
Expand Down

0 comments on commit 13dcbe4

Please sign in to comment.