call method

Future<Map<String, Object?>> call(
  1. String method,
  2. String path, {
  3. Map<String, Object?>? body,
  4. Duration timeout = const Duration(seconds: 30),
})

Calls path on the runner within timeout; throws XcTestRunnerError with the runner's own reason on failure. A slow call only makes the runner suspect: the next call first waits for it to answer, and replaces it only if it stays silent, is stopped or is gone.

Implementation

Future<Map<String, Object?>> call(String method, String path,
    {Map<String, Object?>? body, Duration timeout = const Duration(seconds: 30)}) async {
  if (_dead) {
    await _recover(settle: false);
  } else if (_suspect) {
    await _recover(settle: true);
  } else if (_recovery != null) {
    await _recovery;
  }
  final generation = _generation;
  final (int, Map<String, Object?>) reply;
  try {
    reply = await _send(method, path, body, timeout);
    _suspect = false;
  } on Object catch (e) {
    final verdict = await _noteFailure(e, generation);
    throw XcTestRunnerError('the XCTest runner did not answer $method $path',
        detail: '$e',
        errorKind: e is TimeoutException ? GlintErrorKind.toolTimeout : GlintErrorKind.backendToolError,
        nextSteps: switch (verdict) {
          _Verdict.dead => const ['the runner is gone or stopped; the next call replaces it with a fresh one'],
          _Verdict.suspect => const [
              'the runner may only be busy: retry once, the next call waits for it before deciding',
              'if it repeats, attach again to restart the runner',
            ],
          _Verdict.replaced => const ['the runner was replaced while this call ran: retry'],
        });
  }
  final (code, json) = reply;
  if (code != 200) {
    throw XcTestRunnerError('the XCTest runner refused $method $path: ${json['error'] ?? code}',
        detail: json['detail'] as String?);
  }
  return json;
}