diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-08-09 09:41:25 +0200 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-08-11 18:17:19 +0200 |
commit | 2fb313c9b6ff46d241e94e7a9eddbd6a1e698e03 (patch) | |
tree | c326752e06b99a26158d58aced01e9939988a85c /src/csharp | |
parent | c152d6628a17285cdf05748ecbbc8f39cd770ff8 (diff) |
fix warnings in Grpc.Core.Tests
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ClientServerTest.cs | 44 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/CompressionTest.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs | 8 | ||||
-rwxr-xr-x | src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj | 1 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/HalfcloseTest.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/MockServiceHelper.cs | 14 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/PerformanceTest.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs | 8 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs | 17 | ||||
-rw-r--r-- | src/csharp/Grpc.Core.Tests/TimeoutsTest.cs | 8 |
12 files changed, 60 insertions, 56 deletions
diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs index 0cb9288131..4d4c682634 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => { context.Status = new Status(StatusCode.Unauthenticated, ""); - return ""; + return Task.FromResult(""); }); var ex = Assert.Throws<RpcException>(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); @@ -168,9 +168,10 @@ namespace Grpc.Core.Tests helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(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<string, string>(async (request, responseStream, context) => - { - }); + helper.ServerStreamingHandler = new ServerStreamingServerMethod<string, string>((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<string, string>(async (request, responseStream, context) => + helper.ServerStreamingHandler = new ServerStreamingServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => { context.Status = new Status(StatusCode.Unknown, nonAsciiString); - return ""; + return Task.FromResult(""); }); var ex = Assert.Throws<RpcException>(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); @@ -409,9 +409,9 @@ namespace Grpc.Core.Tests [Test] public void ServerCallContext_PeerInfoPresent() { - helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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 0b28433b98..9254cb998d 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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 5a55ad1bbb..c8bc372202 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (requestStream, context) => @@ -135,10 +135,10 @@ namespace Grpc.Core.Tests [Test] public async Task SuppressDeadlinePropagation() { - helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((request, context) => { Assert.AreEqual(DateTime.MaxValue, context.Deadline); - return "PASS"; + return Task.FromResult("PASS"); }); helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>(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 9be77c8875..6df68fda58 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 @@ <PackageId>Grpc.Core.Tests</PackageId> <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);portable-net45</PackageTargetFallback> <RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <ItemGroup> diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs index 02554dcea5..5fc8fb694a 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<string, string>(async (requestStream, context) => + helper.ClientStreamingHandler = new ClientStreamingServerMethod<string, string>((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 6dac2de071..27c2fa8bf0 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<CompletionQueueEvent>()); } } } diff --git a/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs b/src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs index d368c795d9..c2ece97ba0 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<Timespec>()); } [Test] diff --git a/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs b/src/csharp/Grpc.Core.Tests/MockServiceHelper.cs index 925fb20833..7f4677d57f 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<string, string>(async (request, context) => + unaryHandler = new UnaryServerMethod<string, string>((request, context) => { context.Status = defaultStatus; - return ""; + return Task.FromResult(""); }); - clientStreamingHandler = new ClientStreamingServerMethod<string, string>(async (requestStream, context) => + clientStreamingHandler = new ClientStreamingServerMethod<string, string>((requestStream, context) => { context.Status = defaultStatus; - return ""; + return Task.FromResult(""); }); - serverStreamingHandler = new ServerStreamingServerMethod<string, string>(async (request, responseStream, context) => + serverStreamingHandler = new ServerStreamingServerMethod<string, string>((request, responseStream, context) => { context.Status = defaultStatus; + return TaskUtils.CompletedTask; }); - duplexStreamingHandler = new DuplexStreamingServerMethod<string, string>(async (requestStream, responseStream, context) => + duplexStreamingHandler = new DuplexStreamingServerMethod<string, string>((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 2420b47a87..4b1d745284 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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 67dbcf8f09..e318ee44f4 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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 fb18198945..9a828f307e 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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 8f0d6b866d..b89c1afcc3 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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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<string, string>(async (request, context) => + helper.UnaryHandler = new UnaryServerMethod<string, string>((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"); } |