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); } }
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!"); }
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); }
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); }
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."); } }
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); } }
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); }