Exemplo n.º 1
0
        public async Task DuplexStream_SendToUnimplementedMethodAfterResponseReceived_MoveNextThrowsError()
        {
            // Arrange
            var client = new UnimplementedService.UnimplementedServiceClient(Channel);

            // This is in a loop to verify a hang that existed in HttpClient when the request is not read to completion
            // https://github.com/dotnet/corefx/issues/39586
            for (var i = 0; i < 100; i++)
            {
                Logger.LogInformation("Iteration " + i);

                // Act
                var call = client.DuplexData();

                // Response will only be headers so the call is "done" on the server side
                await call.ResponseHeadersAsync.DefaultTimeout();

                await call.RequestStream.CompleteAsync().DefaultTimeout();

                var ex = await ExceptionAssert.ThrowsAsync <RpcException>(() => call.ResponseStream.MoveNext()).DefaultTimeout();

                var status = call.GetStatus();

                // Assert
                Assert.AreEqual(StatusCode.Unimplemented, ex.StatusCode);
                Assert.AreEqual(StatusCode.Unimplemented, status.StatusCode);
            }
        }
Exemplo n.º 2
0
        public static void RunUnimplementedService(UnimplementedService.UnimplementedServiceClient client)
        {
            Console.WriteLine("running unimplemented_service");
            var e = Assert.Throws <RpcException>(() => client.UnimplementedCall(new Empty()));

            Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode);
            Console.WriteLine("Passed!");
        }
Exemplo n.º 3
0
        public async Task DuplexStream_SendToUnimplementedMethod_ThrowError()
        {
            SetExpectedErrorsFilter(writeContext =>
            {
                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "ErrorSendingMessage" &&
                    writeContext.State.ToString() == "Error sending message.")
                {
                    return(true);
                }

                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "GrpcStatusError" &&
                    writeContext.State.ToString() == "Call failed with gRPC error status. Status code: 'Unimplemented', Message: 'Service is unimplemented.'.")
                {
                    return(true);
                }

                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "WriteMessageError" &&
                    writeContext.Message == "Error writing message.")
                {
                    return(true);
                }

                return(false);
            });

            // Arrange
            var client = new UnimplementedService.UnimplementedServiceClient(Channel);

            // Act
            var call = client.DuplexData();

            await ExceptionAssert.ThrowsAsync <Exception>(async() =>
            {
                await call.RequestStream.WriteAsync(new UnimplementeDataMessage
                {
                    Data = ByteString.CopyFrom(new byte[1024 * 64])
                }).DefaultTimeout();

                await call.RequestStream.WriteAsync(new UnimplementeDataMessage
                {
                    Data = ByteString.CopyFrom(new byte[1024 * 64])
                }).DefaultTimeout();
            });

            await call.ResponseHeadersAsync.DefaultTimeout();

            // Assert
            Assert.AreEqual(StatusCode.Unimplemented, call.GetStatus().StatusCode);
        }
Exemplo n.º 4
0
        public async Task DuplexStream_SendToUnimplementedMethod_ThrowError()
        {
            SetExpectedErrorsFilter(writeContext =>
            {
                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "ErrorSendingMessage" &&
                    writeContext.State.ToString() == "Error sending message.")
                {
                    return(true);
                }

                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.HttpContentClientStreamWriter" &&
                    writeContext.EventId.Name == "WriteMessageError" &&
                    writeContext.Message == "Error writing message.")
                {
                    return(true);
                }

                return(false);
            });

            // Arrange
            var client = new UnimplementedService.UnimplementedServiceClient(Channel);

            // Act
            var call = client.DuplexData();

            await TestHelpers.AssertIsTrueRetryAsync(async() =>
            {
                try
                {
                    await call.RequestStream.WriteAsync(new UnimplementeDataMessage
                    {
                        Data = ByteString.CopyFrom(CreateTestData(1024 * 64))
                    }).DefaultTimeout();
                    return(false);
                }
                catch
                {
                    return(true);
                }
            }, "Write until error.", Logger);

            await call.ResponseHeadersAsync.DefaultTimeout();

            // Assert
            Assert.AreEqual(StatusCode.Unimplemented, call.GetStatus().StatusCode);
        }
Exemplo n.º 5
0
        private static async Task CallUnimplemented(GrpcChannel channel)
        {
            var client = new UnimplementedService.UnimplementedServiceClient(channel);

            var reply = client.DuplexData();

            try
            {
                await reply.ResponseStream.MoveNext();

                throw new Exception("Expected error status.");
            }
            catch (RpcException ex) when(ex.StatusCode == StatusCode.Unimplemented)
            {
                Console.WriteLine("Unimplemented status correctly returned.");
            }
        }
Exemplo n.º 6
0
        public async Task DuplexStream_SendToUnimplementedMethodAfterResponseReceived_MoveNextThrowsError()
        {
            SetExpectedErrorsFilter(writeContext =>
            {
                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "GrpcStatusError" &&
                    writeContext.State.ToString() == "Call failed with gRPC error status. Status code: 'Unimplemented', Message: 'Service is unimplemented.'.")
                {
                    return(true);
                }

                return(false);
            });

            // Arrange
            var client = new UnimplementedService.UnimplementedServiceClient(Channel);

            // This is in a loop to verify a hang that existed in HttpClient when the request is not read to completion
            // https://github.com/dotnet/corefx/issues/39586
            for (var i = 0; i < 100; i++)
            {
                Logger.LogInformation("Iteration " + i);

                // Act
                var call = client.DuplexData();

                // Response will only be headers so the call is "done" on the server side
                await call.ResponseHeadersAsync.DefaultTimeout();

                await call.RequestStream.CompleteAsync();

                var ex = await ExceptionAssert.ThrowsAsync <RpcException>(() => call.ResponseStream.MoveNext());

                var status = call.GetStatus();

                // Assert
                Assert.AreEqual(StatusCode.Unimplemented, ex.StatusCode);
                Assert.AreEqual(StatusCode.Unimplemented, status.StatusCode);
            }
        }
Exemplo n.º 7
0
        public async Task DuplexStream_SendToUnimplementedMethod_ThrowError()
        {
            SetExpectedErrorsFilter(writeContext =>
            {
                if (writeContext.LoggerName == "Grpc.Net.Client.Internal.GrpcCall" &&
                    writeContext.EventId.Name == "ErrorSendingMessage" &&
                    writeContext.State.ToString() == "Error sending message.")
                {
                    return(true);
                }

                return(false);
            });

            // Arrange
            var client = new UnimplementedService.UnimplementedServiceClient(Channel);

            // Act
            var call = client.DuplexData();

            var ex = await ExceptionAssert.ThrowsAsync <RpcException>(async() =>
            {
                await call.RequestStream.WriteAsync(new UnimplementeDataMessage
                {
                    Data = ByteString.CopyFrom(new byte[1024 * 64])
                }).DefaultTimeout();

                await call.RequestStream.WriteAsync(new UnimplementeDataMessage
                {
                    Data = ByteString.CopyFrom(new byte[1024 * 64])
                }).DefaultTimeout();
            });

            // Assert
            Assert.AreEqual(StatusCode.Cancelled, ex.StatusCode);
        }