async Task <int> RunTest(NetworkErrorExecutionRetryPolicy subject, Func <int, bool> evaluator)
        {
            var attempts = 0;
            await subject.Execute(new Request(), CancellationToken.None, (_1, _2) =>
            {
                attempts += 1;

                var result = evaluator(attempts);
                if (result)
                {
                    return(Task.FromResult(ResponseStub.CreateSuccess()));
                }
                else
                {
                    throw new SocketException();
                }
            });

            return(attempts);
        }
예제 #2
0
        async Task <int> RunTest(ThrottleExecutionRetryPolicy subject, Func <int, bool> evaluator)
        {
            var attempts = 0;

            await subject.Execute(new Request(), CancellationToken.None, (_1, _2) =>
            {
                attempts += 1;

                var result = evaluator(attempts);
                if (result)
                {
                    return(Task.FromResult(ResponseStub.CreateSuccess()));
                }
                else
                {
                    return(Task.FromResult(ResponseStub.CreateErrorResponse(ErrorCode.RequestThrottled)));
                }
            });

            return(attempts);
        }