Example #1
0
        public async Task ManyStreamingServerCallsSingleClientTest()
        {
            GrpcCore.Server server = this.StartSimpleServiceServer();

            GrpcCore.Channel channel = new GrpcCore.Channel($"127.0.0.1:{GrpcTestPort}", GrpcCore.ChannelCredentials.Insecure);
            var client = new SimpleCoreService.SimpleCoreServiceClient(channel);

            List <Task> activeCalls      = new List <Task>();
            const int   TotalClientCalls = 100;
            const int   ClientId         = 0;
            TaskCompletionSource <bool> tasksQueuedCompletionSource = new TaskCompletionSource <bool>();

            var callsCounter = new CallsCounter {
                nTotalCalls = TotalClientCalls, tasksQueueTask = tasksQueuedCompletionSource.Task
            };

            this.activeCallCountersDictionary.Add(ClientId, callsCounter);

            for (int i = 0; i < 100; i++)
            {
                activeCalls.Add(MakeStreamingServerCalls(client, ClientId, 10, 10));
                lock (callsCounter)
                {
                    callsCounter.nActiveCalls++;
                }
            }
            Assert.AreEqual(TotalClientCalls, callsCounter.nActiveCalls);
            tasksQueuedCompletionSource.SetResult(true);

            await Task.WhenAll(activeCalls);

            Assert.AreEqual(0, callsCounter.nActiveCalls);

            await server.ShutdownAsync();
        }
Example #2
0
        private static async Task MakeStreamingServerCalls(SimpleCoreService.SimpleCoreServiceClient client, int clientId, int initialValue, int nResponses)
        {
            using (var streamingCall = client.ServerStreamTest(new StreamRequest {
                ClientId = clientId, StartValue = 10
            }))
            {
                int expectedValue = 10;
                while (await streamingCall.ResponseStream.MoveNext(CancellationToken.None))
                {
                    Assert.AreEqual(expectedValue, streamingCall.ResponseStream.Current.Value);
                    expectedValue++;
                }

                Assert.AreEqual(expectedValue, initialValue + nResponses);
            }
        }