fix warnings in Grpc.Core.Tests

pull/12127/head
Jan Tattermusch 7 years ago
parent c152d6628a
commit 2fb313c9b6
  1. 44
      src/csharp/Grpc.Core.Tests/ClientServerTest.cs
  2. 4
      src/csharp/Grpc.Core.Tests/CompressionTest.cs
  3. 8
      src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs
  4. 1
      src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
  5. 4
      src/csharp/Grpc.Core.Tests/HalfcloseTest.cs
  6. 2
      src/csharp/Grpc.Core.Tests/Internal/CompletionQueueEventTest.cs
  7. 2
      src/csharp/Grpc.Core.Tests/Internal/TimespecTest.cs
  8. 14
      src/csharp/Grpc.Core.Tests/MockServiceHelper.cs
  9. 4
      src/csharp/Grpc.Core.Tests/PerformanceTest.cs
  10. 8
      src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs
  11. 17
      src/csharp/Grpc.Core.Tests/ThreadingModelTest.cs
  12. 8
      src/csharp/Grpc.Core.Tests/TimeoutsTest.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),

@ -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));

@ -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) =>

@ -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>

@ -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());

@ -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>());
}
}
}

@ -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]

@ -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;
});
}

@ -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();

@ -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");

@ -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");

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

Loading…
Cancel
Save