public void Should_cancel_remaining_requests_when_receiving_accepted_result()
        {
            DropSynchronizationContext();

            var tokens = new List <CancellationToken>();

            sender
            .When(s => s.SendToReplicaAsync(Arg.Any <Uri>(), Arg.Any <Request>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>()))
            .Do(info => tokens.Add(info.Arg <CancellationToken>()));

            strategy = new ParallelRequestStrategy(int.MaxValue);

            var sendTask = strategy.SendAsync(request, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            CompleteRequest(replicas.Last(), ResponseVerdict.Accept);

            sendTask.GetAwaiter().GetResult();

            tokens.Should().HaveCount(replicas.Length);

            foreach (var t in tokens)
            {
                t.IsCancellationRequested.Should().BeTrue();
            }
        }
Ejemplo n.º 2
0
        public void Should_fire_initial_requests_to_all_replicas_if_parallelism_level_is_greater_than_replicas_count()
        {
            strategy = new ParallelRequestStrategy(int.MaxValue);

            strategy.SendAsync(request, parameters, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            sender.ReceivedCalls().Should().HaveCount(replicas.Length);

            foreach (var replica in replicas)
            {
                sender.Received(1).SendToReplicaAsync(replica, request, Arg.Any <TimeSpan?>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>());
            }
        }
        public void Should_immediately_fire_several_requests_to_reach_parallelism_level()
        {
            DropSynchronizationContext();

            strategy.SendAsync(request, sender, Budget.Infinite, replicas, replicas.Length, token);

            sender.ReceivedCalls().Should().HaveCount(3);
        }
Ejemplo n.º 4
0
        public void Should_ignore_connection_timeout()
        {
            strategy = new ParallelRequestStrategy(int.MaxValue);

            parameters = parameters.WithConnectionTimeout(5.Seconds());

            strategy.SendAsync(request, parameters, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            sender.ReceivedCalls().Should().HaveCount(replicas.Length);

            foreach (var replica in replicas)
            {
                sender.Received(1).SendToReplicaAsync(replica, Arg.Any <Request>(), null, Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>());
            }
        }