Class ProtoReadiness

Namespace
ProtoTest.Core
Assembly
ProtoTest.Core.dll

The readiness checks and the wait loop the host, containers and applications share.

public static class ProtoReadiness
Inheritance
ProtoReadiness
Inherited Members

Methods

Http(Uri, Func<HttpResponseMessage, bool>?, TimeSpan?, Action<string>?)

Ready when an HTTP GET answers. By default any response - including a 404 - proves the address is serving; pass ready to demand a health endpoint or a status. Pass onFailure to observe why an attempt failed (the last reason feeds the timeout failure WaitAsync(string, Func<CancellationToken, ValueTask<bool>>, TimeSpan, TimeSpan, CancellationToken, Func<string?>?) builds).

public static Func<CancellationToken, ValueTask<bool>> Http(Uri url, Func<HttpResponseMessage, bool>? ready = null, TimeSpan? requestTimeout = null, Action<string>? onFailure = null)

Parameters

url Uri
ready Func<HttpResponseMessage, bool>
requestTimeout TimeSpan?
onFailure Action<string>

Returns

Func<CancellationToken, ValueTask<bool>>

Tcp(string, int)

Ready when a TCP connection to the endpoint succeeds.

public static Func<CancellationToken, ValueTask<bool>> Tcp(string host, int port)

Parameters

host string
port int

Returns

Func<CancellationToken, ValueTask<bool>>

WaitAsync(string, Func<CancellationToken, ValueTask<bool>>, TimeSpan, TimeSpan, CancellationToken, Func<string?>?)

Polls a check until it returns true or the timeout expires. Exceptions count as "not ready yet" and are remembered as the last error, so a refused connection while a container boots is normal; a timeout throws with the name, the attempts and the last error (from an exception the check threw or from describeLastError). The wait rides PollAsync<T>(Func<CancellationToken, ValueTask<T>>, Func<T, bool>, TimeSpan, TimeSpan, CancellationToken), so readiness shares one interval and deadline rule with every other wait in the framework.

public static ValueTask<ProtoReadinessResult> WaitAsync(string name, Func<CancellationToken, ValueTask<bool>> check, TimeSpan timeout, TimeSpan interval, CancellationToken cancellationToken = default, Func<string?>? describeLastError = null)

Parameters

name string
check Func<CancellationToken, ValueTask<bool>>
timeout TimeSpan
interval TimeSpan
cancellationToken CancellationToken
describeLastError Func<string>

Returns

ValueTask<ProtoReadinessResult>