waitUntilReady method

  1. @override
Future<void> waitUntilReady(
  1. WaitStrategyTarget target
)
override

Polls the container's log output until message appears times times.

Throws TimeoutException when startupTimeout elapses without a match. Throws StateError when the container exits before the pattern is found.

Implementation

@override
Future<void> waitUntilReady(WaitStrategyTarget target) async {
  final pattern = switch (message) {
    final RegExp r => r,
    _ => RegExp(message.toString(), multiLine: true),
  };

  final ready = await poll(() async {
    await target.reload();
    final (stdout, stderr) = await target.logs();
    final stdoutStr = utf8.decode(stdout, allowMalformed: true);
    final stderrStr = utf8.decode(stderr, allowMalformed: true);

    bool check(String text) {
      final matches = pattern.allMatches(text);
      return matches.length >= times;
    }

    if (predicateStreamsAnd) {
      return check(stdoutStr) && check(stderrStr);
    }
    return check(stdoutStr) || check(stderrStr);
  });

  if (!ready) {
    if (!notExitedStatuses.contains(target.status)) {
      throw StateError(
        'Container exited before log message found. Status: ${target.status}',
      );
    }
    throw TimeoutException(
      'Log message not found within $startupTimeout. '
      'Container status: ${target.status}',
    );
  }
}