From 603a9a06353f5e53092e6d0bd2db2ec995ae1731 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Sep 2018 17:59:38 +0200 Subject: [PATCH] add tests for sync unary --- .../Grpc.Core.Tests/Internal/AsyncCallTest.cs | 18 ++++++++++++++++++ .../Grpc.Core.Tests/Internal/FakeNativeCall.cs | 1 + 2 files changed, 19 insertions(+) diff --git a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs index 961b75c0b51..775849d89b6 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs @@ -124,6 +124,24 @@ namespace Grpc.Core.Internal.Tests Assert.IsTrue(fakeCall.IsDisposed); } + [Test] + public void SyncUnary_RequestSerializationExceptionDoesntLeakResources() + { + string nullRequest = null; // will throw when serializing + Assert.Throws(typeof(ArgumentNullException), () => asyncCall.UnaryCall(nullRequest)); + Assert.AreEqual(0, channel.GetCallReferenceCount()); + Assert.IsTrue(fakeCall.IsDisposed); + } + + [Test] + public void SyncUnary_StartCallFailureDoesntLeakResources() + { + fakeCall.MakeStartCallFail(); + Assert.Throws(typeof(InvalidOperationException), () => asyncCall.UnaryCall("request1")); + Assert.AreEqual(0, channel.GetCallReferenceCount()); + Assert.IsTrue(fakeCall.IsDisposed); + } + [Test] public void ClientStreaming_StreamingReadNotAllowed() { diff --git a/src/csharp/Grpc.Core.Tests/Internal/FakeNativeCall.cs b/src/csharp/Grpc.Core.Tests/Internal/FakeNativeCall.cs index 42536dd0c1a..ef67918dabb 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/FakeNativeCall.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/FakeNativeCall.cs @@ -109,6 +109,7 @@ namespace Grpc.Core.Internal.Tests public void StartUnary(BatchContextSafeHandle ctx, byte[] payload, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags callFlags) { + StartCallMaybeFail(); throw new NotImplementedException(); }