diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs index 0cb9288131d..4d4c682634e 100644 --- a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs @@ -57,9 +57,9 @@ namespace Grpc.Core.Tests [Test] public async Task UnaryCall() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { - return request; + return Task.FromResult(request); }); Assert.AreEqual("ABC", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "ABC")); @@ -124,10 +124,10 @@ namespace Grpc.Core.Tests [Test] public void UnaryCall_ServerHandlerSetsStatus() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { context.Status = new Status(StatusCode.Unauthenticated, ""); - return ""; + return Task.FromResult(""); }); var ex = Assert.Throws(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); @@ -168,9 +168,10 @@ namespace Grpc.Core.Tests helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => { string result = ""; - await requestStream.ForEachAsync(async (request) => + await requestStream.ForEachAsync((request) => { result += request; + return TaskUtils.CompletedTask; }); await Task.Delay(100); return result; @@ -203,9 +204,7 @@ namespace Grpc.Core.Tests [Test] public async Task ServerStreamingCall_EndOfStreamIsIdempotent() { - helper.ServerStreamingHandler = new ServerStreamingServerMethod(async (request, responseStream, context) => - { - }); + helper.ServerStreamingHandler = new ServerStreamingServerMethod((request, responseStream, context) => TaskUtils.CompletedTask); var call = Calls.AsyncServerStreamingCall(helper.CreateServerStreamingCall(), ""); @@ -214,11 +213,12 @@ namespace Grpc.Core.Tests } [Test] - public async Task ServerStreamingCall_ErrorCanBeAwaitedTwice() + public void ServerStreamingCall_ErrorCanBeAwaitedTwice() { - helper.ServerStreamingHandler = new ServerStreamingServerMethod(async (request, responseStream, context) => + helper.ServerStreamingHandler = new ServerStreamingServerMethod((request, responseStream, context) => { context.Status = new Status(StatusCode.InvalidArgument, ""); + return TaskUtils.CompletedTask; }); var call = Calls.AsyncServerStreamingCall(helper.CreateServerStreamingCall(), ""); @@ -343,7 +343,7 @@ namespace Grpc.Core.Tests [Test] public async Task AsyncUnaryCall_EchoMetadata() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { foreach (Metadata.Entry metadataEntry in context.RequestHeaders) { @@ -352,7 +352,7 @@ namespace Grpc.Core.Tests context.ResponseTrailers.Add(metadataEntry); } } - return ""; + return Task.FromResult(""); }); var headers = new Metadata @@ -395,10 +395,10 @@ namespace Grpc.Core.Tests { // some japanese and chinese characters var nonAsciiString = "\u30a1\u30a2\u30a3 \u62b5\u6297\u662f\u5f92\u52b3\u7684"; - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { context.Status = new Status(StatusCode.Unknown, nonAsciiString); - return ""; + return Task.FromResult(""); }); var ex = Assert.Throws(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); @@ -409,9 +409,9 @@ namespace Grpc.Core.Tests [Test] public void ServerCallContext_PeerInfoPresent() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { - return context.Peer; + return Task.FromResult(context.Peer); }); string peer = Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc"); @@ -421,11 +421,11 @@ namespace Grpc.Core.Tests [Test] public void ServerCallContext_HostAndMethodPresent() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.IsTrue(context.Host.Contains(Host)); Assert.AreEqual("/tests.Test/Unary", context.Method); - return "PASS"; + return Task.FromResult("PASS"); }); Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); } @@ -433,11 +433,11 @@ namespace Grpc.Core.Tests [Test] public void ServerCallContext_AuthContextNotPopulated() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.IsFalse(context.AuthContext.IsPeerAuthenticated); Assert.AreEqual(0, context.AuthContext.Properties.Count()); - return "PASS"; + return Task.FromResult("PASS"); }); Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); } @@ -445,9 +445,9 @@ namespace Grpc.Core.Tests [Test] public async Task Channel_WaitForStateChangedAsync() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { - return request; + return Task.FromResult(request); }); Assert.ThrowsAsync(typeof(TaskCanceledException), diff --git a/src/csharp/Grpc.Core.Tests/CompressionTest.cs b/src/csharp/Grpc.Core.Tests/CompressionTest.cs index 0b28433b981..9254cb998dc 100644 --- a/src/csharp/Grpc.Core.Tests/CompressionTest.cs +++ b/src/csharp/Grpc.Core.Tests/CompressionTest.cs @@ -55,10 +55,10 @@ namespace Grpc.Core.Tests [Test] public void WriteOptions_Unary() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { context.WriteOptions = new WriteOptions(WriteFlags.NoCompress); - return request; + return Task.FromResult(request); }); var callOptions = new CallOptions(writeOptions: new WriteOptions(WriteFlags.NoCompress)); diff --git a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs index 5a55ad1bbb2..c8bc372202d 100644 --- a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs +++ b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs @@ -106,11 +106,11 @@ namespace Grpc.Core.Tests public async Task PropagateDeadline() { var deadline = DateTime.UtcNow.AddDays(7); - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.IsTrue(context.Deadline < deadline.AddMinutes(1)); Assert.IsTrue(context.Deadline > deadline.AddMinutes(-1)); - return "PASS"; + return Task.FromResult("PASS"); }); helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => @@ -135,10 +135,10 @@ namespace Grpc.Core.Tests [Test] public async Task SuppressDeadlinePropagation() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.AreEqual(DateTime.MaxValue, context.Deadline); - return "PASS"; + return Task.FromResult("PASS"); }); helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index 9be77c8875d..6df68fda589 100755 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -10,6 +10,7 @@ Grpc.Core.Tests $(PackageTargetFallback);portable-net45 1.0.4 + true diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs index 02554dcea50..5fc8fb694ab 100644 --- a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs +++ b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs @@ -62,9 +62,9 @@ namespace Grpc.Core.Tests [Test] public async Task HalfcloseAfterFullclose_ClientStreamingCall() { - helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => + helper.ClientStreamingHandler = new ClientStreamingServerMethod((requestStream, context) => { - return "PASS"; + return Task.FromResult("PASS"); }); var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall()); diff --git a/src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs b/src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs index 6dac2de0715..27c2fa8bf01 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs @@ -31,7 +31,7 @@ namespace Grpc.Core.Internal.Tests [Test] public void CreateAndDestroy() { - Assert.AreEqual(CompletionQueueEvent.NativeSize, Marshal.SizeOf(typeof(CompletionQueueEvent))); + Assert.AreEqual(CompletionQueueEvent.NativeSize, Marshal.SizeOf()); } } } diff --git a/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs b/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs index d368c795d92..c2ece97ba0e 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs @@ -60,7 +60,7 @@ namespace Grpc.Core.Internal.Tests [Test] public void TimespecSizeIsNativeSize() { - Assert.AreEqual(Timespec.NativeSize, Marshal.SizeOf(typeof(Timespec))); + Assert.AreEqual(Timespec.NativeSize, Marshal.SizeOf()); } [Test] diff --git a/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs b/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs index 925fb20833a..7f4677d57fb 100644 --- a/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs +++ b/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs @@ -96,26 +96,28 @@ namespace Grpc.Core.Tests var defaultStatus = new Status(StatusCode.Unknown, "Default mock implementation. Please provide your own."); - unaryHandler = new UnaryServerMethod(async (request, context) => + unaryHandler = new UnaryServerMethod((request, context) => { context.Status = defaultStatus; - return ""; + return Task.FromResult(""); }); - clientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => + clientStreamingHandler = new ClientStreamingServerMethod((requestStream, context) => { context.Status = defaultStatus; - return ""; + return Task.FromResult(""); }); - serverStreamingHandler = new ServerStreamingServerMethod(async (request, responseStream, context) => + serverStreamingHandler = new ServerStreamingServerMethod((request, responseStream, context) => { context.Status = defaultStatus; + return TaskUtils.CompletedTask; }); - duplexStreamingHandler = new DuplexStreamingServerMethod(async (requestStream, responseStream, context) => + duplexStreamingHandler = new DuplexStreamingServerMethod((requestStream, responseStream, context) => { context.Status = defaultStatus; + return TaskUtils.CompletedTask; }); } diff --git a/src/csharp/Grpc.Core.Tests/PerformanceTest.cs b/src/csharp/Grpc.Core.Tests/PerformanceTest.cs index 2420b47a877..4b1d745284a 100644 --- a/src/csharp/Grpc.Core.Tests/PerformanceTest.cs +++ b/src/csharp/Grpc.Core.Tests/PerformanceTest.cs @@ -61,9 +61,9 @@ namespace Grpc.Core.Tests var profiler = new BasicProfiler(); Profilers.SetForCurrentThread(profiler); - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { - return request; + return Task.FromResult(request); }); var callDetails = helper.CreateUnaryCall(); diff --git a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs index 67dbcf8f09d..e318ee44f4f 100644 --- a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs +++ b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs @@ -138,10 +138,10 @@ namespace Grpc.Core.Tests [Test] public void WriteResponseHeaders_NullNotAllowed() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.ThrowsAsync(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null)); - return "PASS"; + return Task.FromResult("PASS"); }); Assert.AreEqual("PASS", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "")); @@ -158,7 +158,7 @@ namespace Grpc.Core.Tests await context.WriteResponseHeadersAsync(headers); Assert.Fail(); } - catch (InvalidOperationException expected) + catch (InvalidOperationException) { } return "PASS"; @@ -178,7 +178,7 @@ namespace Grpc.Core.Tests await context.WriteResponseHeadersAsync(headers); Assert.Fail(); } - catch (InvalidOperationException expected) + catch (InvalidOperationException) { } await responseStream.WriteAsync("B"); diff --git a/src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs b/src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs index fb181989455..9a828f307e2 100644 --- a/src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs +++ b/src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs @@ -50,13 +50,14 @@ namespace Grpc.Core.Tests [Test] public void BlockingCallInServerHandlerDoesNotDeadlock() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { int recursionDepth = int.Parse(request); if (recursionDepth <= 0) { - return "SUCCESS"; + return Task.FromResult("SUCCESS"); } - return Calls.BlockingUnaryCall(helper.CreateUnaryCall(), (recursionDepth - 1).ToString()); + var response = Calls.BlockingUnaryCall(helper.CreateUnaryCall(), (recursionDepth - 1).ToString()); + return Task.FromResult(response); }); int maxRecursionDepth = Environment.ProcessorCount * 2; // make sure we have more pending blocking calls than threads in GrpcThreadPool @@ -66,12 +67,12 @@ namespace Grpc.Core.Tests [Test] public void HandlerDoesNotRunOnGrpcThread() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { if (IsRunningOnGrpcThreadPool()) { - return "Server handler should not run on gRPC threadpool thread."; + return Task.FromResult("Server handler should not run on gRPC threadpool thread."); } - return request; + return Task.FromResult(request); }); Assert.AreEqual("ABC", Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "ABC")); @@ -80,9 +81,9 @@ namespace Grpc.Core.Tests [Test] public async Task ContinuationDoesNotRunOnGrpcThread() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { - return request; + return Task.FromResult(request); }); await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "ABC"); diff --git a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs index 8f0d6b866d9..b89c1afcc35 100644 --- a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs +++ b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs @@ -57,10 +57,10 @@ namespace Grpc.Core.Tests [Test] public void InfiniteDeadline() { - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { Assert.AreEqual(DateTime.MaxValue, context.Deadline); - return "PASS"; + return Task.FromResult("PASS"); }); // no deadline specified, check server sees infinite deadline @@ -75,13 +75,13 @@ namespace Grpc.Core.Tests { var clientDeadline = DateTime.UtcNow + TimeSpan.FromDays(7); - helper.UnaryHandler = new UnaryServerMethod(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod((request, context) => { // A fairly relaxed check that the deadline set by client and deadline seen by server // are in agreement. C core takes care of the work with transferring deadline over the wire, // so we don't need an exact check here. Assert.IsTrue(Math.Abs((clientDeadline - context.Deadline).TotalMilliseconds) < 5000); - return "PASS"; + return Task.FromResult("PASS"); }); Calls.BlockingUnaryCall(helper.CreateUnaryCall(new CallOptions(deadline: clientDeadline)), "abc"); }