waitUntilReady method
Attempts a TCP connection to port on each poll cycle.
Throws TimeoutException when startupTimeout elapses without a successful TCP connection.
Implementation
@override
Future<void> waitUntilReady(WaitStrategyTarget target) async {
final host = await target.containerHostIp();
final ready = await poll(
() async {
try {
final socket = await Socket.connect(
host,
await target.exposedPort(port),
).timeout(const Duration(seconds: 1));
await socket.close();
return true;
} on SocketException {
return false;
} on TimeoutException {
return false;
}
},
transientExceptions: [SocketException, TimeoutException],
);
if (!ready) {
throw TimeoutException(
'Port $port not available within $startupTimeout',
);
}
}