Exemplo n.º 1
0
        /// <nodoc />
        public async Task <BoolResult> StartupAsync(Context context, int waitMs)
        {
            try
            {
                if (!LocalContentServer.EnsureRunning(context, _scenario, waitMs))
                {
                    throw new ClientCanRetryException(context, $"{nameof(GrpcClient)} failed to detect running service for scenario {_scenario} during startup");
                }

                context.Always($"Starting up GRPC client against service on port {_grpcPort}");

                HelloResponse helloResponse;
                using (var ct = new CancellationTokenSource(waitMs))
                {
                    helloResponse = await RunClientActionAndThrowIfFailedAsync(
                        context,
                        async() => await _client.HelloAsync(
                            new HelloRequest(),
                            cancellationToken: ct.Token));
                }

                if (helloResponse.Success)
                {
                    _serviceCapabilities = (Capabilities)helloResponse.Capabilities;
                }
                else
                {
                    return(new BoolResult("Failed to connect to service for unknown reason."));
                }
            }
            catch (Exception ex) when(!(ex is ClientCanRetryException))
            {
                // The caller's retry policy needs to see ClientCanRetryExceptions in order to properly retry
                return(new BoolResult(ex));
            }

            return(BoolResult.Success);
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 protected override AsyncUnaryCall <HelloResponse> HelloAsync(HelloRequest helloRequest, CancellationToken token)
 {
     return(_client.HelloAsync(helloRequest, cancellationToken: token));
 }