Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions docs/api/create_docker_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Starting a container or creating a resource (such as a network or a volume) can

```csharp title="Canceling container start after one minute"
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromMinutes(1));
await _container.StartAsync(timeoutCts.Token);
await _container.StartAsync(timeoutCts.Token)
.ConfigureAwait(false);
```

## Getting log messages
Expand All @@ -86,7 +87,8 @@ Testcontainers for .NET provides two approaches for retrieving log messages from
The `GetLogsAsync` method is available through the `IContainer` interface. It allows you to fetch logs from a container for a specific time range or from the beginning until the present. This approach is useful for retrieving logs after a test has run, especially when troubleshooting issues or failures.

```csharp title="Getting all log messages"
var (stdout, stderr) = await _container.GetLogsAsync();
var (stdout, stderr) = await _container.GetLogsAsync()
.ConfigureAwait(false);
```

The `WithOutputConsumer` method is part of the `ContainerBuilder` class and is used to continuously forward container log messages to a specified output consumer. This approach provides real-time access to logs as the container runs.
Expand Down
2 changes: 1 addition & 1 deletion examples/Flyway/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ItemGroup>
<!-- Unit and integration test dependencies: -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.7.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="xunit" Version="2.9.2"/>
<!-- Third-party client dependencies to connect and interact with the containers: -->
Expand Down
2 changes: 1 addition & 1 deletion examples/Respawn/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ItemGroup>
<!-- Unit and integration test dependencies: -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.7.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="xunit" Version="2.9.2"/>
<!-- Third-party client dependencies to connect and interact with the containers: -->
Expand Down
2 changes: 1 addition & 1 deletion examples/WeatherForecast/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Unit and integration test dependencies: -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.2.0"/>
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.7.0"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2"/>
<PackageVersion Include="xunit" Version="2.9.2"/>
<!-- Third-party client dependencies to connect and interact with the containers: -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public WeatherForecastContainer()
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", WeatherForecastImage.CertificateFilePath)
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", WeatherForecastImage.CertificatePassword)
.WithEnvironment("ConnectionStrings__PostgreSQL", postgreSqlConnectionString)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(WeatherForecastImage.HttpsPort))
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(WeatherForecastImage.HttpsPort))
.Build();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Testcontainers.Weaviate/WeaviateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected override WeaviateBuilder Init()
.WithEnvironment("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true")
.WithEnvironment("PERSISTENCE_DATA_PATH", "/var/lib/weaviate")
.WithWaitStrategy(Wait.ForUnixContainer()
.UntilPortIsAvailable(WeaviateHttpPort)
.UntilPortIsAvailable(WeaviateGrpcPort)
.UntilInternalTcpPortIsAvailable(WeaviateHttpPort)
.UntilInternalTcpPortIsAvailable(WeaviateGrpcPort)
.UntilHttpRequestIsSucceeded(request =>
request.ForPath("/v1/.well-known/ready").ForPort(WeaviateHttpPort)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ public interface IWaitForContainerOS
[PublicAPI]
IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string> command, Action<IWaitStrategy> waitStrategyModifier = null);

/// <summary>
/// Waits until the port is available.
/// </summary>
/// <param name="port">The port to be checked.</param>
/// <param name="waitStrategyModifier">The wait strategy modifier to cancel the readiness check.</param>
/// <returns>A configured instance of <see cref="IWaitForContainerOS" />.</returns>
[PublicAPI]
[Obsolete("Use UntilInternalTcpPortIsAvailable or UntilExternalTcpPortIsAvailable instead. This method corresponds to the internal variant.")]
IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null);

/// <summary>
/// Waits until a TCP port is available from within the container itself.
/// This verifies that a service inside the container is listening on the specified port.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ protected WaitForContainerOS()
/// <inheritdoc />
public abstract IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string> command, Action<IWaitStrategy> waitStrategyModifier = null);

/// <inheritdoc />
public abstract IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null);

/// <inheritdoc />
public abstract IWaitForContainerOS UntilInternalTcpPortIsAvailable(int containerPort, Action<IWaitStrategy> waitStrategyModifier = null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public override IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string>
return AddCustomWaitStrategy(new UntilUnixCommandIsCompleted(command.ToArray()), waitStrategyModifier);
}

/// <inheritdoc />
public override IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null)
{
return UntilInternalTcpPortIsAvailable(port, waitStrategyModifier);
}

/// <inheritdoc />
public override IWaitForContainerOS UntilInternalTcpPortIsAvailable(int containerPort, Action<IWaitStrategy> waitStrategyModifier = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public override IWaitForContainerOS UntilCommandIsCompleted(IEnumerable<string>
return AddCustomWaitStrategy(new UntilWindowsCommandIsCompleted(command.ToArray()), waitStrategyModifier);
}

/// <inheritdoc />
public override IWaitForContainerOS UntilPortIsAvailable(int port, Action<IWaitStrategy> waitStrategyModifier = null)
{
return UntilInternalTcpPortIsAvailable(port, waitStrategyModifier);
}

/// <inheritdoc />
public override IWaitForContainerOS UntilInternalTcpPortIsAvailable(int containerPort, Action<IWaitStrategy> waitStrategyModifier = null)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Testcontainers/Containers/PortForwarding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ protected override PortForwardingBuilder Init()
.WithPortBinding(SshdPort, true)
.WithUsername("root")
.WithPassword("root")
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(SshdPort));
.WithWaitStrategy(Wait.ForUnixContainer()
.UntilInternalTcpPortIsAvailable(SshdPort)
.UntilExternalTcpPortIsAvailable(SshdPort));
}

/// <inheritdoc />
Expand Down
4 changes: 3 additions & 1 deletion src/Testcontainers/Containers/SocatBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public override SocatContainer Build()
.Select(item => string.Format(argument, item.Key, item.Value)));

var waitStrategy = DockerResourceConfiguration.Targets
.Aggregate(Wait.ForUnixContainer(), (waitStrategy, item) => waitStrategy.UntilPortIsAvailable(item.Key));
.Aggregate(Wait.ForUnixContainer(), (waitStrategy, item) => waitStrategy
.UntilInternalTcpPortIsAvailable(item.Key)
.UntilExternalTcpPortIsAvailable(item.Key));

var socatBuilder = WithCommand(command).WithWaitStrategy(waitStrategy);
return new SocatContainer(socatBuilder.DockerResourceConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public UntilInternalTcpPortIsAvailable()
.WithImage(CommonImages.ServerCore)
.WithEntrypoint("PowerShell", "-NoLogo", "-Command")
.WithCommand("$tcpListener = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Any, 8080); $tcpListener.Start(); Start-Sleep -Seconds 120")
.WithWaitStrategy(Wait.ForWindowsContainer().UntilPortIsAvailable(8080))
.WithWaitStrategy(Wait.ForWindowsContainer().UntilInternalTcpPortIsAvailable(8080))
.Build())
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public sealed class GetContainerLogsTest : IAsyncLifetime
{
private readonly IContainer _container = new ContainerBuilder()
.WithImage("amazon/dynamodb-local:1.20.0")
.WithWaitStrategy(Wait.ForUnixContainer()
.UntilPortIsAvailable(8000))
.WithWaitStrategy(Wait.ForUnixContainer().UntilInternalTcpPortIsAvailable(8000))
.Build();

[Fact]
Expand Down