Wait Class

Provides factory methods for the built-in IWaitStrategy implementations.

public static class Wait

Methods

NameDescription
ForAll(IWaitStrategy[])Runs the strategies concurrently and waits until all of them complete. The first failure stops the others and fails the wait.
ForAny(IWaitStrategy[])Runs the strategies concurrently and waits until one of them completes, then stops the others. The wait fails only when all of them fail.
ForCommand(IEnumerable<string>, Action<PollingWaitStrategyOptions>?)Waits until a command run inside the container exits with code 0. The command is run again after each failure.
ForCommand(string[])Waits until a command run inside the container exits with code 0. The command is run again after each failure.
ForDelay(TimeSpan)Waits for a fixed amount of time.
ForHealthcheck(Action<PollingWaitStrategyOptions>?)Waits until the container runtime reports the health check of the container (the HEALTHCHECK instruction of its image) as healthy. The wait fails at once when the container has no health check or becomes unhealthy.
ForHttp(int, string, Action<HttpWaitStrategyOptions>?)Waits until an HTTP request to the host port mapped to containerPort gets an expected response, by default a 2xx status code.
ForLogMessage(string, int)Waits until a log line contains the specified text.
ForLogMessage(Regex, int)Waits until a log line matches the specified pattern.
ForPort(int)Waits until a TCP connection can be established on the host port mapped to containerPort.

ForAll(IWaitStrategy[])

Wait.cs

Runs the strategies concurrently and waits until all of them complete. The first failure stops the others and fails the wait.

public static IWaitStrategy ForAll(params IWaitStrategy[] strategies)

Parameters

strategies IWaitStrategy[]
The strategies to run.

Returns

IWaitStrategy A wait strategy.

ForAny(IWaitStrategy[])

Wait.cs

Runs the strategies concurrently and waits until one of them completes, then stops the others. The wait fails only when all of them fail.

public static IWaitStrategy ForAny(params IWaitStrategy[] strategies)

Parameters

strategies IWaitStrategy[]
The strategies to run.

Returns

IWaitStrategy A wait strategy.

ForCommand overloads

ForCommand(IEnumerable<string>, Action<PollingWaitStrategyOptions>?)

Wait.cs

Waits until a command run inside the container exits with code 0. The command is run again after each failure.

public static IWaitStrategy ForCommand(IEnumerable<string> command, Action<PollingWaitStrategyOptions>? configure)
Parameters
command IEnumerable<string>
The command and its arguments. The first element is the executable.
configure Action<PollingWaitStrategyOptions>?
Configures the delay between two runs of the command.
Returns

IWaitStrategy A wait strategy.

ForCommand(string[])

Wait.cs

Waits until a command run inside the container exits with code 0. The command is run again after each failure.

public static IWaitStrategy ForCommand(params string[] command)
Parameters
command string[]
The command and its arguments. The first element is the executable.
Returns

IWaitStrategy A wait strategy.

ForDelay(TimeSpan)

Wait.cs

Waits for a fixed amount of time.

public static IWaitStrategy ForDelay(TimeSpan delay)

Parameters

delay TimeSpan
The delay to wait.

Returns

IWaitStrategy A wait strategy.

ForHealthcheck(Action<PollingWaitStrategyOptions>?)

Wait.cs

Waits until the container runtime reports the health check of the container (the HEALTHCHECK instruction of its image) as healthy. The wait fails at once when the container has no health check or becomes unhealthy.

public static IWaitStrategy ForHealthcheck(Action<PollingWaitStrategyOptions>? configure = null)

Parameters

configure Action<PollingWaitStrategyOptions>?
Configures the delay between two inspections of the container.

Returns

IWaitStrategy A wait strategy.

ForHttp(int, string, Action<HttpWaitStrategyOptions>?)

Wait.cs

Waits until an HTTP request to the host port mapped to containerPort gets an expected response, by default a 2xx status code.

public static IWaitStrategy ForHttp(int containerPort, string path = "/", Action<HttpWaitStrategyOptions>? configure = null)

Parameters

containerPort int
The container port to send the request to.
path string
The path, and optionally the query, of the request.
configure Action<HttpWaitStrategyOptions>?
Configures the request and the response that means the container is ready.

Returns

IWaitStrategy A wait strategy.

ForLogMessage overloads

ForLogMessage(string, int)

Wait.cs

Waits until a log line contains the specified text.

public static IWaitStrategy ForLogMessage(string substring, int occurrences = 1)
Parameters
substring string
The text to look for.
occurrences int
The number of matching lines to wait for.
Returns

IWaitStrategy A wait strategy.

ForLogMessage(Regex, int)

Wait.cs

Waits until a log line matches the specified pattern.

public static IWaitStrategy ForLogMessage(Regex pattern, int occurrences = 1)
Parameters
pattern Regex
The pattern to match against each log line.
occurrences int
The number of matching lines to wait for.
Returns

IWaitStrategy A wait strategy.

ForPort(int)

Wait.cs

Waits until a TCP connection can be established on the host port mapped to containerPort.

public static IWaitStrategy ForPort(int containerPort)

Parameters

containerPort int
The container port to probe.

Returns

IWaitStrategy A wait strategy.