public async void ClientRequestsDataFromEachMachineExactlyOnce()
        {
            var request = new TieredRequest
            {
                FanoutTimeoutInMilliseconds = 10,
                MaxFanout = 2
            };

            var allMachines = new List <ServerInfo>();

            foreach (var name in new[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" })
            {
                allMachines.Add(new ServerInfo {
                    Hostname = name, Port = 42
                });
            }
            var seenMachines = new HashSet <ServerInfo>();

            (request.Sources as List <ServerInfo>).AddRange(allMachines);

            DistributedQueryClient.RequesterFactory = new MockHttpRequesterFactory(requestMessage =>
            {
                var requestedSources = MockDataFactory.UnpackRequest <TieredRequest>(requestMessage).Result;
                lock (allMachines)
                {
                    var leaderName = MockDataFactory.ExtractServerInfo(requestMessage.RequestUri);
                    requestedSources.Sources.Add(leaderName);

                    foreach (var name in requestedSources.Sources)
                    {
                        Assert.IsTrue(seenMachines.Add(name));
                    }
                }

                // causes the request to fail (we don't care about the request here, we are just inspecting the request)
                throw new WebException();
            });


            var response = await this.client.CounterQuery("/something", request, null);

            Assert.IsNotNull(response);
            Assert.AreEqual(allMachines.Count, seenMachines.Count);
            Assert.IsTrue(allMachines.All(seenMachines.Contains));
        }
        private static async Task <HttpResponseMessage> GenerateFailureResponse(HttpRequestMessage request,
                                                                                HttpStatusCode responseCode,
                                                                                RequestStatus statusForDownstreamSources)
        {
            var requestMessage = await MockDataFactory.UnpackRequest <TieredRequest>(request);

            var responseContent = new CounterQueryResponse();

            responseContent.RequestDetails = requestMessage.Sources.Select(source =>
                                                                           new RequestDetails
            {
                Server = source,
                Status = statusForDownstreamSources
            }).ToList();

            // add one for the leader
            responseContent.RequestDetails.Add(new RequestDetails
            {
                Server           = MockDataFactory.ExtractServerInfo(request.RequestUri),
                Status           = RequestStatus.ServerFailureResponse,
                HttpResponseCode = (short)responseCode
            });
            return(MockDataFactory.CreateResponse(responseContent, responseCode));
        }