Skip to content

Commit 9b23f05

Browse files
authored
fix(ResourceReaper): Set wait strategy (#1634)
1 parent 1db748d commit 9b23f05

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/Testcontainers/Containers/ResourceReaper.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ static ResourceReaper()
5656
private ResourceReaper(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, IImage resourceReaperImage, IMount dockerSocket, ILogger logger, bool requiresPrivilegedMode)
5757
{
5858
_resourceReaperContainer = new ContainerBuilder(resourceReaperImage)
59-
.WithName($"testcontainers-ryuk-{sessionId:D}")
6059
.WithDockerEndpoint(dockerEndpointAuthConfig)
60+
.WithName($"testcontainers-ryuk-{sessionId:D}")
6161
.WithPrivileged(requiresPrivilegedMode)
6262
.WithAutoRemove(true)
6363
.WithCleanUp(false)
6464
.WithPortBinding(TestcontainersSettings.ResourceReaperPublicHostPort.Invoke(dockerEndpointAuthConfig), RyukPort)
6565
.WithMount(dockerSocket)
6666
.WithLogger(logger)
67+
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Started"))
6768
.Build();
6869

6970
SessionId = sessionId;
@@ -303,6 +304,7 @@ await Task.Delay(TimeSpan.FromSeconds(RetryTimeoutInSeconds), CancellationToken.
303304

304305
using (var tcpClient = new TcpClient())
305306
{
307+
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
306308
tcpClient.LingerState = DiscardAllPendingData;
307309

308310
try
@@ -364,7 +366,7 @@ await Task.Delay(TimeSpan.FromSeconds(RetryTimeoutInSeconds), ct)
364366
#pragma warning restore S907
365367
}
366368

367-
var indexOfNewLine = Array.IndexOf(readBytes, (byte)'\n');
369+
var indexOfNewLine = Array.IndexOf(readBytes, (byte)'\n', 0, numberOfBytes);
368370

369371
if (indexOfNewLine == -1)
370372
{
@@ -389,7 +391,9 @@ await messageBuffer.WriteAsync(readBytes.AsMemory(0, indexOfNewLine), ct)
389391
.ConfigureAwait(false);
390392
#endif
391393

392-
hasAcknowledge = "ack".Equals(Encoding.ASCII.GetString(messageBuffer.ToArray()), StringComparison.OrdinalIgnoreCase);
394+
var buffer = messageBuffer.GetBuffer();
395+
396+
hasAcknowledge = "ack".Equals(Encoding.ASCII.GetString(buffer, 0, (int)messageBuffer.Length), StringComparison.OrdinalIgnoreCase);
393397
messageBuffer.SetLength(0);
394398
}
395399
}

0 commit comments

Comments
 (0)