From a8a73fd8d894db440db12317ca057bfe20676e8a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 14:15:04 -0700 Subject: [PATCH 01/21] update nuget dependencies to nunit3 --- src/csharp/.nuget/packages.config | 2 +- .../Grpc.Core.Tests/Grpc.Core.Tests.csproj | 21 +++---------------- src/csharp/Grpc.Core.Tests/packages.config | 3 +-- .../Grpc.Examples.Tests.csproj | 5 +++-- .../Grpc.Examples.Tests/packages.config | 2 +- src/csharp/Grpc.Examples/Grpc.Examples.csproj | 3 +++ src/csharp/Grpc.Examples/packages.config | 2 +- .../Grpc.HealthCheck.Tests.csproj | 5 +++-- .../Grpc.HealthCheck.Tests/packages.config | 2 +- .../Grpc.IntegrationTesting.csproj | 5 +++-- .../Grpc.IntegrationTesting/packages.config | 2 +- 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/csharp/.nuget/packages.config b/src/csharp/.nuget/packages.config index acb43ae4b3d..6154b3561f4 100644 --- a/src/csharp/.nuget/packages.config +++ b/src/csharp/.nuget/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index 3bfd49b10fe..5f0efb48890 100644 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -35,24 +35,9 @@ ..\keys\Grpc.snk - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll - False - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll - False - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - False - - - ..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - False + + False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config index 610831dfe1e..e019bcbd7e0 100644 --- a/src/csharp/Grpc.Core.Tests/packages.config +++ b/src/csharp/Grpc.Core.Tests/packages.config @@ -1,6 +1,5 @@  - - + \ No newline at end of file diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj index 9aeab059f95..baf25770900 100644 --- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj +++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj @@ -41,8 +41,9 @@ False ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll diff --git a/src/csharp/Grpc.Examples.Tests/packages.config b/src/csharp/Grpc.Examples.Tests/packages.config index ed30d2d428e..28010f412f8 100644 --- a/src/csharp/Grpc.Examples.Tests/packages.config +++ b/src/csharp/Grpc.Examples.Tests/packages.config @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/src/csharp/Grpc.Examples/Grpc.Examples.csproj b/src/csharp/Grpc.Examples/Grpc.Examples.csproj index 15b04c8d8b7..f0a0aa3a266 100644 --- a/src/csharp/Grpc.Examples/Grpc.Examples.csproj +++ b/src/csharp/Grpc.Examples/Grpc.Examples.csproj @@ -41,6 +41,9 @@ False ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll + diff --git a/src/csharp/Grpc.Examples/packages.config b/src/csharp/Grpc.Examples/packages.config index dfb8304ad10..a424cd2ea02 100644 --- a/src/csharp/Grpc.Examples/packages.config +++ b/src/csharp/Grpc.Examples/packages.config @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj index bb6488b4f12..62474b46911 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj +++ b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj @@ -41,8 +41,9 @@ False ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll diff --git a/src/csharp/Grpc.HealthCheck.Tests/packages.config b/src/csharp/Grpc.HealthCheck.Tests/packages.config index 47280939791..caf99ecfdbe 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/packages.config +++ b/src/csharp/Grpc.HealthCheck.Tests/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index 7ea80b11f0d..9c56608427f 100644 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -68,8 +68,9 @@ False ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll diff --git a/src/csharp/Grpc.IntegrationTesting/packages.config b/src/csharp/Grpc.IntegrationTesting/packages.config index 0ae8bf4e707..a18137cbbf4 100644 --- a/src/csharp/Grpc.IntegrationTesting/packages.config +++ b/src/csharp/Grpc.IntegrationTesting/packages.config @@ -8,5 +8,5 @@ - + \ No newline at end of file From e331da2277a7a52deceeee17baa79ea4c7feefe8 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 11:05:39 -0700 Subject: [PATCH 02/21] make Grpc.Core.Tests work with NUnit3 --- src/csharp/Grpc.Core.Tests/ChannelTest.cs | 4 ++-- src/csharp/Grpc.Core.Tests/ClientServerTest.cs | 10 +++++----- src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs | 2 +- src/csharp/Grpc.Core.Tests/HalfcloseTest.cs | 2 +- src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs | 2 +- src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs | 8 ++++---- src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs index ed0ec14df5c..6330f50faed 100644 --- a/src/csharp/Grpc.Core.Tests/ChannelTest.cs +++ b/src/csharp/Grpc.Core.Tests/ChannelTest.cs @@ -70,7 +70,7 @@ namespace Grpc.Core.Tests public void WaitForStateChangedAsync_InvalidArgument() { var channel = new Channel("localhost", ChannelCredentials.Insecure); - Assert.Throws(typeof(ArgumentException), () => channel.WaitForStateChangedAsync(ChannelState.FatalFailure)); + Assert.ThrowsAsync(typeof(ArgumentException), async () => await channel.WaitForStateChangedAsync(ChannelState.FatalFailure)); channel.ShutdownAsync().Wait(); } @@ -87,7 +87,7 @@ namespace Grpc.Core.Tests { var channel = new Channel("localhost", ChannelCredentials.Insecure); channel.ShutdownAsync().Wait(); - Assert.Throws(typeof(InvalidOperationException), () => channel.ShutdownAsync().GetAwaiter().GetResult()); + Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await channel.ShutdownAsync()); } } } diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs index 77f6a63156b..6c13a4fa483 100644 --- a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs @@ -93,7 +93,7 @@ namespace Grpc.Core.Tests var ex = Assert.Throws(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unknown, ex.Status.StatusCode); - var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); + var ex2 = Assert.ThrowsAsync(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unknown, ex2.Status.StatusCode); } @@ -108,7 +108,7 @@ namespace Grpc.Core.Tests var ex = Assert.Throws(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode); - var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); + var ex2 = Assert.ThrowsAsync(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unauthenticated, ex2.Status.StatusCode); } @@ -124,7 +124,7 @@ namespace Grpc.Core.Tests var ex = Assert.Throws(() => Calls.BlockingUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unauthenticated, ex.Status.StatusCode); - var ex2 = Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); + var ex2 = Assert.ThrowsAsync(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "abc")); Assert.AreEqual(StatusCode.Unauthenticated, ex2.Status.StatusCode); } @@ -204,7 +204,7 @@ namespace Grpc.Core.Tests await barrier.Task; // make sure the handler has started. cts.Cancel(); - var ex = Assert.Throws(async () => await call.ResponseAsync); + var ex = Assert.ThrowsAsync(async () => await call.ResponseAsync); Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode); } @@ -290,7 +290,7 @@ namespace Grpc.Core.Tests return request; }); - Assert.Throws(typeof(TaskCanceledException), + Assert.ThrowsAsync(typeof(TaskCanceledException), async () => await channel.WaitForStateChangedAsync(channel.State, DateTime.UtcNow.AddMilliseconds(10))); var stateChangedTask = channel.WaitForStateChangedAsync(channel.State); diff --git a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs index 90c510ec61f..cec8c7ce6bb 100644 --- a/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs +++ b/src/csharp/Grpc.Core.Tests/ContextPropagationTest.cs @@ -105,7 +105,7 @@ namespace Grpc.Core.Tests var parentCall = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall(new CallOptions(cancellationToken: cts.Token))); await readyToCancelTcs.Task; cts.Cancel(); - Assert.Throws(typeof(RpcException), async () => await parentCall); + Assert.ThrowsAsync(typeof(RpcException), async () => await parentCall); Assert.AreEqual("CHILD_CALL_CANCELLED", await successTcs.Task); } diff --git a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs index fe6edb858bb..b4cb451d944 100644 --- a/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs +++ b/src/csharp/Grpc.Core.Tests/HalfcloseTest.cs @@ -91,7 +91,7 @@ namespace Grpc.Core.Tests await call.RequestStream.CompleteAsync(); // Second attempt to close from client is not allowed. - Assert.Throws(typeof(InvalidOperationException), async () => await call.RequestStream.CompleteAsync()); + Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await call.RequestStream.CompleteAsync()); } } } diff --git a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs index 543f6375df1..60530d32508 100644 --- a/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs +++ b/src/csharp/Grpc.Core.Tests/Internal/AsyncCallTest.cs @@ -84,7 +84,7 @@ namespace Grpc.Core.Internal.Tests Assert.AreEqual(StatusCode.Internal, asyncCall.GetStatus().StatusCode); Assert.IsNull(asyncCall.GetTrailers()); - var ex = Assert.Throws(() => resultTask.GetAwaiter().GetResult()); + var ex = Assert.ThrowsAsync(async () => await resultTask); Assert.AreEqual(StatusCode.Internal, ex.Status.StatusCode); } diff --git a/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs b/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs index 37fb36946af..0663e77d1ea 100644 --- a/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs +++ b/src/csharp/Grpc.Core.Tests/MarshallingErrorsTest.cs @@ -112,7 +112,7 @@ namespace Grpc.Core.Tests }); var call = Calls.AsyncServerStreamingCall(helper.CreateServerStreamingCall(), "REQUEST"); - var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); Assert.AreEqual(StatusCode.Internal, ex.Status.StatusCode); } @@ -134,7 +134,7 @@ namespace Grpc.Core.Tests { helper.ClientStreamingHandler = new ClientStreamingServerMethod(async (requestStream, context) => { - Assert.Throws(async () => await requestStream.MoveNext()); + Assert.ThrowsAsync(async () => await requestStream.MoveNext()); return "RESPONSE"; }); @@ -153,7 +153,7 @@ namespace Grpc.Core.Tests [Test] public void RequestSerializationError_AsyncUnary() { - Assert.Throws(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "UNSERIALIZABLE_VALUE")); + Assert.ThrowsAsync(async () => await Calls.AsyncUnaryCall(helper.CreateUnaryCall(), "UNSERIALIZABLE_VALUE")); } [Test] @@ -166,7 +166,7 @@ namespace Grpc.Core.Tests }); var call = Calls.AsyncClientStreamingCall(helper.CreateClientStreamingCall()); await call.RequestStream.WriteAsync("A"); - Assert.Throws(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE")); + Assert.ThrowsAsync(async () => await call.RequestStream.WriteAsync("UNSERIALIZABLE_VALUE")); await call.RequestStream.WriteAsync("B"); await call.RequestStream.CompleteAsync(); diff --git a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs index a1648f36712..772beadd4a3 100644 --- a/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs +++ b/src/csharp/Grpc.Core.Tests/ResponseHeadersTest.cs @@ -155,7 +155,7 @@ namespace Grpc.Core.Tests { helper.UnaryHandler = new UnaryServerMethod(async (request, context) => { - Assert.Throws(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null)); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => await context.WriteResponseHeadersAsync(null)); return "PASS"; }); From 6c0dee8b0de56613f9988f0dbfac2e46d9024653 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 12:14:09 -0700 Subject: [PATCH 03/21] migrate Grpc.Examples.Tests to NUnit3 --- src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs index 290d42808e7..875202b9509 100644 --- a/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs +++ b/src/csharp/Grpc.Examples.Tests/MathClientServerTests.cs @@ -149,7 +149,7 @@ namespace Math.Tests using (var call = client.Fib(new FibArgs { Limit = 0 }, deadline: DateTime.UtcNow.AddMilliseconds(500))) { - var ex = Assert.Throws(async () => await call.ResponseStream.ToListAsync()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.ToListAsync()); // We can't guarantee the status code always DeadlineExceeded. See issue #2685. Assert.Contains(ex.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); From 9f19bd3eb1c01fbde43375db2f51dfdb0f9504ec Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 13:32:30 -0700 Subject: [PATCH 04/21] migrate Grpc.IntegrationTesting to NUnit3 --- .../Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs | 6 +++--- src/csharp/Grpc.IntegrationTesting/InteropClient.cs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs index 99aa7290301..5fd0e14e78d 100644 --- a/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs +++ b/src/csharp/Grpc.IntegrationTesting/GeneratedServiceBaseTest.cs @@ -84,7 +84,7 @@ namespace Grpc.IntegrationTesting { var call = client.StreamingInputCall(); - var ex = Assert.Throws(async () => await call); + var ex = Assert.ThrowsAsync(async () => await call); Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode); } @@ -93,7 +93,7 @@ namespace Grpc.IntegrationTesting { var call = client.StreamingOutputCall(new StreamingOutputCallRequest()); - var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode); } @@ -102,7 +102,7 @@ namespace Grpc.IntegrationTesting { var call = client.FullDuplexCall(); - var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); Assert.AreEqual(StatusCode.Unimplemented, ex.Status.StatusCode); } diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index 7ca52219360..54365179603 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -445,7 +445,7 @@ namespace Grpc.IntegrationTesting await Task.Delay(1000); cts.Cancel(); - var ex = Assert.Throws(async () => await call.ResponseAsync); + var ex = Assert.ThrowsAsync(async () => await call.ResponseAsync); Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode); } Console.WriteLine("Passed!"); @@ -471,7 +471,7 @@ namespace Grpc.IntegrationTesting cts.Cancel(); - var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); Assert.AreEqual(StatusCode.Cancelled, ex.Status.StatusCode); } Console.WriteLine("Passed!"); @@ -493,7 +493,7 @@ namespace Grpc.IntegrationTesting // Deadline was reached before write has started. Eat the exception and continue. } - var ex = Assert.Throws(async () => await call.ResponseStream.MoveNext()); + var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); Assert.AreEqual(StatusCode.DeadlineExceeded, ex.Status.StatusCode); } Console.WriteLine("Passed!"); @@ -572,7 +572,7 @@ namespace Grpc.IntegrationTesting await call.RequestStream.WriteAsync(request); await call.RequestStream.CompleteAsync(); - var e = Assert.Throws(async () => await call.ResponseStream.ToListAsync()); + var e = Assert.ThrowsAsync(async () => await call.ResponseStream.ToListAsync()); Assert.AreEqual(StatusCode.Unknown, e.Status.StatusCode); Assert.AreEqual(echoStatus.Message, e.Status.Detail); } From fd8d2735266bf9f8d481973956ea823aaadbb853 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 15:11:07 -0700 Subject: [PATCH 05/21] cleanup of C# interop dockerimage --- tools/dockerfile/grpc_interop_csharp/Dockerfile | 10 +++------- tools/dockerfile/grpc_interop_csharp/build_interop.sh | 4 +--- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/dockerfile/grpc_interop_csharp/Dockerfile b/tools/dockerfile/grpc_interop_csharp/Dockerfile index 3789cd32038..93cd25010ef 100644 --- a/tools/dockerfile/grpc_interop_csharp/Dockerfile +++ b/tools/dockerfile/grpc_interop_csharp/Dockerfile @@ -80,13 +80,9 @@ RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat # Install dependencies RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y \ mono-devel \ - nunit \ - nunit-console \ - monodevelop - -# Download NuGet -RUN cd /var/local && wget www.nuget.org/NuGet.exe -ENV NUGET mono /var/local/NuGet.exe + ca-certificates-mono \ + nuget \ + && apt-get clean # Define the default command. CMD ["bash"] diff --git a/tools/dockerfile/grpc_interop_csharp/build_interop.sh b/tools/dockerfile/grpc_interop_csharp/build_interop.sh index dc1f7a331ab..fd5436c44ff 100755 --- a/tools/dockerfile/grpc_interop_csharp/build_interop.sh +++ b/tools/dockerfile/grpc_interop_csharp/build_interop.sh @@ -40,6 +40,4 @@ cp -r /var/local/jenkins/service_account $HOME || true cd /var/local/git/grpc # build C# interop client & server -make CONFIG=dbg grpc_csharp_ext -(cd src/csharp && mono /var/local/NuGet.exe restore Grpc.sln) -(cd src/csharp && xbuild Grpc.sln) +tools/run_tests/run_tests.py -l csharp -c dbg --build_only From b323608b2717ed617edcebfca9ffb1249045e141 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 17:08:57 -0700 Subject: [PATCH 06/21] fix test credentials for nunit3 --- .../TestCredentials.cs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs index ce108d808b6..aa54cd38a1d 100644 --- a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs +++ b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs @@ -50,9 +50,29 @@ namespace Grpc.IntegrationTesting { public const string DefaultHostOverride = "foo.test.google.fr"; - public const string ClientCertAuthorityPath = "data/ca.pem"; - public const string ServerCertChainPath = "data/server1.pem"; - public const string ServerPrivateKeyPath = "data/server1.key"; + public static string ClientCertAuthorityPath + { + get + { + return GetPath("data/ca.pem"); + } + } + + public static string ServerCertChainPath + { + get + { + return GetPath("data/server1.pem"); + } + } + + public static string ServerPrivateKeyPath + { + get + { + return GetPath("data/server1.key"); + } + } public static SslCredentials CreateSslCredentials() { @@ -66,5 +86,10 @@ namespace Grpc.IntegrationTesting File.ReadAllText(ServerPrivateKeyPath)); return new SslServerCredentials(new[] { keyCertPair }); } + + private static string GetPath(string relativePath) + { + return Path.Combine(TestContext.CurrentContext.TestDirectory, relativePath); + } } } From f6824c2685af5a3c55868dc23293d663b5bcb403 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 17:18:44 -0700 Subject: [PATCH 07/21] fix run_tests scripts --- tools/run_tests/run_csharp.bat | 7 +++++-- tools/run_tests/run_csharp.sh | 5 ++++- tools/run_tests/run_tests.py | 15 ++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/run_tests/run_csharp.bat b/tools/run_tests/run_csharp.bat index 29c879e23be..025ec034723 100644 --- a/tools/run_tests/run_csharp.bat +++ b/tools/run_tests/run_csharp.bat @@ -5,12 +5,15 @@ setlocal @rem enter src/csharp directory cd /d %~dp0\..\..\src\csharp +rem nunit3-console fails if nunit.framework.dll is not found. +copy packages\NUnit.3.2.0\lib\net45\nunit.framework.dll packages\NUnit.ConsoleRunner.3.2.0\tools\nunit.framework.dll + if not "%CONFIG%" == "gcov" ( - packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe %* || goto :error + packages\NUnit.ConsoleRunner.3.2.0\tools\nunit3-console.exe %* || goto :error ) else ( @rem Run all tests with code coverage - packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"packages\NUnit.Runners.2.6.4\tools\nunit-console-x86.exe" -targetdir:"." -targetargs:"%*" -filter:"+[Grpc.Core]*" -register:user -output:coverage_results.xml || goto :error + packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"packages\NUnit.ConsoleRunner.3.2.0\tools\nunit3-console.exe" -targetdir:"." -targetargs:"%*" -filter:"+[Grpc.Core]*" -register:user -output:coverage_results.xml || goto :error packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe -reports:"coverage_results.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error diff --git a/tools/run_tests/run_csharp.sh b/tools/run_tests/run_csharp.sh index dad44c4e4f6..71cd87411f5 100755 --- a/tools/run_tests/run_csharp.sh +++ b/tools/run_tests/run_csharp.sh @@ -31,7 +31,10 @@ set -ex CONFIG=${CONFIG:-opt} -NUNIT_CONSOLE="mono packages/NUnit.Runners.2.6.4/tools/nunit-console.exe" +NUNIT_CONSOLE="mono packages/NUnit.ConsoleRunner.3.2.0/tools/nunit3-console.exe" + +# nunit3-console fails if nunit.framework.dll is not found. +cp -u src/csharp/packages/NUnit.3.2.0/lib/net45/nunit.framework.dll src/csharp/packages/NUnit.ConsoleRunner.3.2.0/tools/ # change to gRPC repo root cd $(dirname $0)/../.. diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index dfac94660b6..4f3aaca7ecd 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -494,11 +494,16 @@ class CSharpLanguage(object): assembly_files = ['%s/bin/%s/%s.dll' % (a, msbuild_config, a) for a in assemblies] - extra_args = ['-labels'] + assembly_files + # TODO(jtattermusch): use --x86 when needed + + extra_args = ['--labels=All', + '--noresult', + '--workers=1', + '--inprocess'] + assembly_files if self.platform == 'windows': script_name = 'tools\\run_tests\\run_csharp.bat' - extra_args += ['-domain=None'] + extra_args += ['--domain=None'] else: script_name = 'tools/run_tests/run_csharp.sh' @@ -512,11 +517,7 @@ class CSharpLanguage(object): else: specs = [] for test in tests: - cmdline = [script_name, '-run=%s' % test] + extra_args - if self.platform == 'windows': - # use different output directory for each test to prevent - # TestResult.xml clash between parallel test runs. - cmdline += ['-work=test-result/%s' % uuid.uuid4()] + cmdline = [script_name, '--test=%s' % test] + extra_args specs.append(self.config.job_spec(cmdline, None, shortname='csharp.%s' % test, environ=_FORCE_ENVIRON_FOR_WRAPPERS)) From a8ef9c39254c4b37f9b7bdf9c4d03766f1d8818e Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 17:48:40 -0700 Subject: [PATCH 08/21] use correct non-overwrite flag for cp --- tools/run_tests/run_csharp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/run_csharp.sh b/tools/run_tests/run_csharp.sh index 71cd87411f5..7ba21d460ef 100755 --- a/tools/run_tests/run_csharp.sh +++ b/tools/run_tests/run_csharp.sh @@ -34,7 +34,7 @@ CONFIG=${CONFIG:-opt} NUNIT_CONSOLE="mono packages/NUnit.ConsoleRunner.3.2.0/tools/nunit3-console.exe" # nunit3-console fails if nunit.framework.dll is not found. -cp -u src/csharp/packages/NUnit.3.2.0/lib/net45/nunit.framework.dll src/csharp/packages/NUnit.ConsoleRunner.3.2.0/tools/ +cp -n src/csharp/packages/NUnit.3.2.0/lib/net45/nunit.framework.dll src/csharp/packages/NUnit.ConsoleRunner.3.2.0/tools/ # change to gRPC repo root cd $(dirname $0)/../.. From 21451b7af67bebb3510040e1dbc54c63f91941c7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 8 Apr 2016 20:59:34 -0700 Subject: [PATCH 09/21] add NUnitMain to test projects --- .../Grpc.Core.Tests/Grpc.Core.Tests.csproj | 3 +- src/csharp/Grpc.Core.Tests/NUnitMain.cs | 55 +++++++++++++++++++ .../Grpc.Examples.Tests.csproj | 3 +- src/csharp/Grpc.Examples.Tests/NUnitMain.cs | 55 +++++++++++++++++++ .../Grpc.HealthCheck.Tests.csproj | 3 +- .../Grpc.HealthCheck.Tests/NUnitMain.cs | 55 +++++++++++++++++++ .../Grpc.IntegrationTesting.csproj | 3 +- .../Grpc.IntegrationTesting/NUnitMain.cs | 55 +++++++++++++++++++ 8 files changed, 228 insertions(+), 4 deletions(-) create mode 100644 src/csharp/Grpc.Core.Tests/NUnitMain.cs create mode 100644 src/csharp/Grpc.Examples.Tests/NUnitMain.cs create mode 100644 src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs create mode 100644 src/csharp/Grpc.IntegrationTesting/NUnitMain.cs diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index 5f0efb48890..d5f21b09d29 100644 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -4,7 +4,7 @@ Debug AnyCPU {86EC5CB4-4EA2-40A2-8057-86542A0353BB} - Library + Exe Grpc.Core.Tests Grpc.Core.Tests v4.5 @@ -79,6 +79,7 @@ + diff --git a/src/csharp/Grpc.Core.Tests/NUnitMain.cs b/src/csharp/Grpc.Core.Tests/NUnitMain.cs new file mode 100644 index 00000000000..494bb0a33ff --- /dev/null +++ b/src/csharp/Grpc.Core.Tests/NUnitMain.cs @@ -0,0 +1,55 @@ +#region Copyright notice and license + +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Reflection; +using NUnit.Common; +using NUnitLite; + +namespace Grpc.Core.Tests +{ + /// + /// Provides entry point for NUnitLite + /// + public class NUnitMain + { + public static void Main(string[] args) + { +#if DOTNET5_4 + new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); +#else + new AutoRun().Execute(args); +#endif + } + } +} diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj index baf25770900..4923a96545e 100644 --- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj +++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj @@ -6,7 +6,7 @@ 10.0.0 2.0 {143B1C29-C442-4BE0-BF3F-A8F92288AC9F} - Library + Exe Grpc.Examples.Tests Grpc.Examples.Tests v4.5 @@ -57,6 +57,7 @@ + diff --git a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs new file mode 100644 index 00000000000..0f234086d8c --- /dev/null +++ b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs @@ -0,0 +1,55 @@ +#region Copyright notice and license + +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Reflection; +using NUnit.Common; +using NUnitLite; + +namespace Grpc.Examples.Tests +{ + /// + /// Provides entry point for NUnitLite + /// + public class NUnitMain + { + public static void Main(string[] args) + { +#if DOTNET5_4 + new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); +#else + new AutoRun().Execute(args); +#endif + } + } +} diff --git a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj index 62474b46911..3698dbc4090 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj +++ b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {F8C6D937-C44B-4EE3-A431-B0FBAEACE47D} - Library + Exe Properties Grpc.HealthCheck.Tests Grpc.HealthCheck.Tests @@ -60,6 +60,7 @@ + diff --git a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs new file mode 100644 index 00000000000..8d5182155ee --- /dev/null +++ b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs @@ -0,0 +1,55 @@ +#region Copyright notice and license + +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Reflection; +using NUnit.Common; +using NUnitLite; + +namespace Grpc.HealthCheck.Tests +{ + /// + /// Provides entry point for NUnitLite + /// + public class NUnitMain + { + public static void Main(string[] args) + { +#if DOTNET5_4 + new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); +#else + new AutoRun().Execute(args); +#endif + } + } +} diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index 9c56608427f..e454c3e5c8f 100644 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -4,7 +4,7 @@ Debug AnyCPU {C61154BA-DD4A-4838-8420-0162A28925E0} - Library + Exe Grpc.IntegrationTesting Grpc.IntegrationTesting v4.5 @@ -117,6 +117,7 @@ + diff --git a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs new file mode 100644 index 00000000000..45fa0e5d0cb --- /dev/null +++ b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs @@ -0,0 +1,55 @@ +#region Copyright notice and license + +// Copyright 2016, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Reflection; +using NUnit.Common; +using NUnitLite; + +namespace Grpc.IntegrationTesting +{ + /// + /// Provides entry point for NUnitLite + /// + public class NUnitMain + { + public static void Main(string[] args) + { +#if DOTNET5_4 + new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); +#else + new AutoRun().Execute(args); +#endif + } + } +} From a49a72dc0dfb59295a3ba0ae59febbcfe8257ff0 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 12:50:35 -0700 Subject: [PATCH 10/21] use NUnitLite to run nunit tests --- .../Grpc.Core.Tests/Grpc.Core.Tests.csproj | 11 ++--- src/csharp/Grpc.Core.Tests/packages.config | 1 + .../Grpc.Examples.Tests.csproj | 16 +++---- .../Grpc.Examples.Tests/packages.config | 11 ++--- .../Grpc.HealthCheck.Tests.csproj | 23 +++++----- .../Grpc.HealthCheck.Tests/packages.config | 1 + .../Grpc.IntegrationTesting.csproj | 45 +++++++++---------- .../Grpc.IntegrationTesting/packages.config | 1 + 8 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index d5f21b09d29..d9b93e9eb59 100644 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -35,15 +35,16 @@ ..\keys\Grpc.snk - - False + + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll - - - False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll + + ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll + diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config index e019bcbd7e0..c5cfde2ab73 100644 --- a/src/csharp/Grpc.Core.Tests/packages.config +++ b/src/csharp/Grpc.Core.Tests/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file diff --git a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj index 4923a96545e..cfe668b6bed 100644 --- a/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj +++ b/src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 10.0.0 - 2.0 {143B1C29-C442-4BE0-BF3F-A8F92288AC9F} Exe Grpc.Examples.Tests @@ -37,19 +35,19 @@ ..\keys\Grpc.snk - - False + + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll - - - False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll + + ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll + diff --git a/src/csharp/Grpc.Examples.Tests/packages.config b/src/csharp/Grpc.Examples.Tests/packages.config index 28010f412f8..ce030f9d777 100644 --- a/src/csharp/Grpc.Examples.Tests/packages.config +++ b/src/csharp/Grpc.Examples.Tests/packages.config @@ -1,6 +1,7 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj index 3698dbc4090..0bea9c03e7a 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj +++ b/src/csharp/Grpc.HealthCheck.Tests/Grpc.HealthCheck.Tests.csproj @@ -1,5 +1,5 @@  - + Debug @@ -37,14 +37,6 @@ ..\keys\Grpc.snk - - False - ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - - False - ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll - @@ -52,6 +44,15 @@ + + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll + + + ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll + @@ -64,11 +65,11 @@ - {ccc4440e-49f7-4790-b0af-feabb0837ae7} + {CCC4440E-49F7-4790-B0AF-FEABB0837AE7} Grpc.Core - {aa5e328a-8835-49d7-98ed-c29f2b3049f0} + {AA5E328A-8835-49D7-98ED-C29F2B3049F0} Grpc.HealthCheck diff --git a/src/csharp/Grpc.HealthCheck.Tests/packages.config b/src/csharp/Grpc.HealthCheck.Tests/packages.config index caf99ecfdbe..8066d8fcebd 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/packages.config +++ b/src/csharp/Grpc.HealthCheck.Tests/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index e454c3e5c8f..c16d0e5c5d0 100644 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -38,48 +38,43 @@ ..\keys\Grpc.snk - - False - ..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll - ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll - - False + + ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll + + + + + + + ..\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll + + ..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.dll - - False + ..\packages\Google.Apis.Auth.1.11.1\lib\net45\Google.Apis.Auth.PlatformServices.dll - - False + ..\packages\Google.Apis.Core.1.11.1\lib\net45\Google.Apis.Core.dll - - False + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll - - - False + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll - - False + ..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll - - - False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll - - - + + ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll + diff --git a/src/csharp/Grpc.IntegrationTesting/packages.config b/src/csharp/Grpc.IntegrationTesting/packages.config index a18137cbbf4..3fef67dca4f 100644 --- a/src/csharp/Grpc.IntegrationTesting/packages.config +++ b/src/csharp/Grpc.IntegrationTesting/packages.config @@ -9,4 +9,5 @@ + \ No newline at end of file From 10e85f1ef7c0f6df55eaa4eee6804c9f0ec3d5eb Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 13:16:37 -0700 Subject: [PATCH 11/21] fix interop tests --- src/csharp/Grpc.IntegrationTesting/TestCredentials.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs index aa54cd38a1d..774563d752f 100644 --- a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs +++ b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs @@ -35,6 +35,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Text.RegularExpressions; using System.Threading.Tasks; using Grpc.Core; @@ -89,7 +90,8 @@ namespace Grpc.IntegrationTesting private static string GetPath(string relativePath) { - return Path.Combine(TestContext.CurrentContext.TestDirectory, relativePath); + var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + return Path.Combine(assemblyDir, relativePath); } } } From 04743d7a0b4e6a27bdab75cccab3201b2d81f95f Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 13:23:47 -0700 Subject: [PATCH 12/21] add Newtonsoft.Json to Grpc.Core.Tests --- src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj | 3 +++ src/csharp/Grpc.Core.Tests/packages.config | 1 + 2 files changed, 4 insertions(+) diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index d9b93e9eb59..0cd059c2327 100644 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -45,6 +45,9 @@ ..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + diff --git a/src/csharp/Grpc.Core.Tests/packages.config b/src/csharp/Grpc.Core.Tests/packages.config index c5cfde2ab73..aa7d951fdc7 100644 --- a/src/csharp/Grpc.Core.Tests/packages.config +++ b/src/csharp/Grpc.Core.Tests/packages.config @@ -1,6 +1,7 @@  + \ No newline at end of file From 31b8316ab9ac69f5d870a74330ccd9dfd1e4ba76 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 14:44:22 -0700 Subject: [PATCH 13/21] make NUnitMain fail on failure --- src/csharp/Grpc.Core.Tests/NUnitMain.cs | 6 +++--- src/csharp/Grpc.Examples.Tests/NUnitMain.cs | 6 +++--- src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs | 6 +++--- src/csharp/Grpc.IntegrationTesting/NUnitMain.cs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/NUnitMain.cs b/src/csharp/Grpc.Core.Tests/NUnitMain.cs index 494bb0a33ff..13e5b27f7bd 100644 --- a/src/csharp/Grpc.Core.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.Core.Tests/NUnitMain.cs @@ -43,12 +43,12 @@ namespace Grpc.Core.Tests /// public class NUnitMain { - public static void Main(string[] args) + public static int Main(string[] args) { #if DOTNET5_4 - new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); + return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else - new AutoRun().Execute(args); + return new AutoRun().Execute(args); #endif } } diff --git a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs index 0f234086d8c..e6b76bcf3ba 100644 --- a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs @@ -43,12 +43,12 @@ namespace Grpc.Examples.Tests /// public class NUnitMain { - public static void Main(string[] args) + public static int Main(string[] args) { #if DOTNET5_4 - new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); + return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else - new AutoRun().Execute(args); + return new AutoRun().Execute(args); #endif } } diff --git a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs index 8d5182155ee..6d77b12fef9 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs @@ -43,12 +43,12 @@ namespace Grpc.HealthCheck.Tests /// public class NUnitMain { - public static void Main(string[] args) + public static int Main(string[] args) { #if DOTNET5_4 - new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); + return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else - new AutoRun().Execute(args); + return new AutoRun().Execute(args); #endif } } diff --git a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs index 45fa0e5d0cb..4db8e158d3c 100644 --- a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs +++ b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs @@ -43,12 +43,12 @@ namespace Grpc.IntegrationTesting /// public class NUnitMain { - public static void Main(string[] args) + public static int Main(string[] args) { #if DOTNET5_4 - new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); + return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else - new AutoRun().Execute(args); + return new AutoRun().Execute(args); #endif } } From 38ed2cfdb588d2f04a9ce7c4bc352f26c534935d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 16:24:16 -0700 Subject: [PATCH 14/21] teach run_tests how to run C# tests with NUnitLite --- tools/run_tests/post_tests_csharp.bat | 21 ++++++ .../{run_csharp.sh => post_tests_csharp.sh} | 27 +++----- tools/run_tests/run_csharp.bat | 30 -------- tools/run_tests/run_tests.py | 69 ++++++++++--------- 4 files changed, 67 insertions(+), 80 deletions(-) create mode 100644 tools/run_tests/post_tests_csharp.bat rename tools/run_tests/{run_csharp.sh => post_tests_csharp.sh} (68%) delete mode 100644 tools/run_tests/run_csharp.bat diff --git a/tools/run_tests/post_tests_csharp.bat b/tools/run_tests/post_tests_csharp.bat new file mode 100644 index 00000000000..a3137aafa1f --- /dev/null +++ b/tools/run_tests/post_tests_csharp.bat @@ -0,0 +1,21 @@ +@rem Runs C# tests for given assembly from command line. The Grpc.sln solution needs to be built before running the tests. + +setlocal + +@rem enter src/csharp directory +cd /d %~dp0\..\..\src\csharp + +@rem Generate code coverage report +@rem TODO(jtattermusch): currently the report list is hardcoded +packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe -reports:"coverage_csharp_*.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error + +@rem Generate the index.html file +echo ^^^^^csharp coverage^^
^
^
>..\..\reports\index.html + +endlocal + +goto :EOF + +:error +echo Failed! +exit /b %errorlevel% diff --git a/tools/run_tests/run_csharp.sh b/tools/run_tests/post_tests_csharp.sh similarity index 68% rename from tools/run_tests/run_csharp.sh rename to tools/run_tests/post_tests_csharp.sh index 7ba21d460ef..bb6f5c6e188 100755 --- a/tools/run_tests/run_csharp.sh +++ b/tools/run_tests/post_tests_csharp.sh @@ -30,26 +30,15 @@ set -ex -CONFIG=${CONFIG:-opt} -NUNIT_CONSOLE="mono packages/NUnit.ConsoleRunner.3.2.0/tools/nunit3-console.exe" - -# nunit3-console fails if nunit.framework.dll is not found. -cp -n src/csharp/packages/NUnit.3.2.0/lib/net45/nunit.framework.dll src/csharp/packages/NUnit.ConsoleRunner.3.2.0/tools/ +if [ "$CONFIG" != "gcov" ] ; then exit ; fi # change to gRPC repo root cd $(dirname $0)/../.. -(cd src/csharp; $NUNIT_CONSOLE $@) - -if [ "$CONFIG" = "gcov" ] -then - # Generate the csharp extension coverage report - gcov objs/gcov/src/csharp/ext/*.o - lcov --base-directory . --directory . -c -o coverage.info - lcov -e coverage.info '**/src/csharp/ext/*' -o coverage.info - genhtml -o reports/csharp_ext_coverage --num-spaces 2 \ - -t 'gRPC C# native extension test coverage' coverage.info \ - --rc genhtml_hi_limit=95 --rc genhtml_med_limit=80 --no-prefix -fi - - +# Generate the csharp extension coverage report +gcov objs/gcov/src/csharp/ext/*.o +lcov --base-directory . --directory . -c -o coverage.info +lcov -e coverage.info '**/src/csharp/ext/*' -o coverage.info +genhtml -o reports/csharp_ext_coverage --num-spaces 2 \ + -t 'gRPC C# native extension test coverage' coverage.info \ + --rc genhtml_hi_limit=95 --rc genhtml_med_limit=80 --no-prefix diff --git a/tools/run_tests/run_csharp.bat b/tools/run_tests/run_csharp.bat deleted file mode 100644 index 025ec034723..00000000000 --- a/tools/run_tests/run_csharp.bat +++ /dev/null @@ -1,30 +0,0 @@ -@rem Runs C# tests for given assembly from command line. The Grpc.sln solution needs to be built before running the tests. - -setlocal - -@rem enter src/csharp directory -cd /d %~dp0\..\..\src\csharp - -rem nunit3-console fails if nunit.framework.dll is not found. -copy packages\NUnit.3.2.0\lib\net45\nunit.framework.dll packages\NUnit.ConsoleRunner.3.2.0\tools\nunit.framework.dll - -if not "%CONFIG%" == "gcov" ( - packages\NUnit.ConsoleRunner.3.2.0\tools\nunit3-console.exe %* || goto :error -) else ( - @rem Run all tests with code coverage - - packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"packages\NUnit.ConsoleRunner.3.2.0\tools\nunit3-console.exe" -targetdir:"." -targetargs:"%*" -filter:"+[Grpc.Core]*" -register:user -output:coverage_results.xml || goto :error - - packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe -reports:"coverage_results.xml" -targetdir:"..\..\reports\csharp_coverage" -reporttypes:"Html;TextSummary" || goto :error - - @rem Generate the index.html file - echo ^^^^^csharp coverage^^
^^ >..\..\reports\index.html -) - -endlocal - -goto :EOF - -:error -echo Failed! -exit /b %errorlevel% diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 4f3aaca7ecd..e2cc3bdfffb 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -486,42 +486,46 @@ class CSharpLanguage(object): def test_specs(self): with open('src/csharp/tests.json') as f: - tests_json = json.load(f) - assemblies = tests_json['assemblies'] - tests = tests_json['tests'] + tests_by_assembly = json.load(f) msbuild_config = _MSBUILD_CONFIG[self.config.build_config] - assembly_files = ['%s/bin/%s/%s.dll' % (a, msbuild_config, a) - for a in assemblies] - - # TODO(jtattermusch): use --x86 when needed - - extra_args = ['--labels=All', + nunit_args = ['--labels=All', '--noresult', - '--workers=1', - '--inprocess'] + assembly_files - + '--workers=1'] if self.platform == 'windows': - script_name = 'tools\\run_tests\\run_csharp.bat' - extra_args += ['--domain=None'] + runtime_cmd = [] else: - script_name = 'tools/run_tests/run_csharp.sh' - - if self.config.build_config == 'gcov': - # On Windows, we only collect C# code coverage. - # On Linux, we only collect coverage for native extension. - # For code coverage all tests need to run as one suite. - return [self.config.job_spec([script_name] + extra_args, None, - shortname='csharp.coverage', - environ=_FORCE_ENVIRON_FOR_WRAPPERS)] - else: - specs = [] - for test in tests: - cmdline = [script_name, '--test=%s' % test] + extra_args - specs.append(self.config.job_spec(cmdline, None, - shortname='csharp.%s' % test, + runtime_cmd = ['mono'] + + specs = [] + for assembly in tests_by_assembly.iterkeys(): + assembly_file = 'src/csharp/%s/bin/%s/%s.exe' % (assembly, msbuild_config, assembly) + if self.config.build_config != 'gcov': + # normally, run each test as a separate process + for test in tests_by_assembly[assembly]: + cmdline = runtime_cmd + [assembly_file, '--test=%s' % test] + nunit_args + specs.append(self.config.job_spec(cmdline, + None, + shortname='csharp.%s' % test, + environ=_FORCE_ENVIRON_FOR_WRAPPERS)) + else: + # for test coverage, run all tests from the same assembly at once + # on Windows, things get more complicated as we need to run the code coverage tool + if self.platform == 'windows': + cmdline = ['packages\OpenCover.4.6.519\tools\OpenCover.Console.exe', + '-target:%s' % assembly_file, + '-targetdir:src\\csharp', + '-targetargs:%s' % ' '.join(nunit_args), + '-filter:+[Grpc.Core]*', + '-register:user', + '-output:coverage_csharp_%s.xml' % assembly] + else: + cmdline = runtime_cmd + [assembly_file] + nunit_args + + specs.append(self.config.job_spec([script_name] + extra_args, None, + shortname='csharp.coverage.%s' % assembly, environ=_FORCE_ENVIRON_FOR_WRAPPERS)) - return specs + return specs def pre_build_steps(self): if self.platform == 'windows': @@ -544,7 +548,10 @@ class CSharpLanguage(object): return [['tools/run_tests/build_csharp.sh']] def post_tests_steps(self): - return [] + if self.platform == 'windows': + return [['tools\\run_tests\\post_tests_csharp.bat']] + else: + return [['tools/run_tests/post_tests_csharp.sh']] def makefile_name(self): return 'Makefile' From 9c3f15c43b3e2b68a239639ef13f50391b98a184 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 16:25:01 -0700 Subject: [PATCH 15/21] improve C# sanity test --- src/csharp/Grpc.Core.Tests/SanityTest.cs | 28 ++++++++++++------------ src/csharp/tests.json | 22 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/SanityTest.cs b/src/csharp/Grpc.Core.Tests/SanityTest.cs index 343ab1e85a1..3830f0cbacf 100644 --- a/src/csharp/Grpc.Core.Tests/SanityTest.cs +++ b/src/csharp/Grpc.Core.Tests/SanityTest.cs @@ -38,6 +38,7 @@ using System.Reflection; using Grpc.Core; using Grpc.Core.Internal; using Grpc.Core.Utils; +using Newtonsoft.Json; using NUnit.Framework; namespace Grpc.Core.Tests @@ -55,27 +56,23 @@ namespace Grpc.Core.Tests [Test] public void TestsJsonUpToDate() { - var testClasses = DiscoverAllTestClasses(); - string testsJson = GetTestsJson(); + var discoveredTests = DiscoverAllTestClasses(); + string discoveredTestsJson = JsonConvert.SerializeObject(discoveredTests, Formatting.Indented); - // we don't have a JSON parser at hand, but check that the test class - // name is contained in the file instead. - foreach (var className in testClasses) { - Assert.IsTrue(testsJson.Contains(className), - string.Format("Test class \"{0}\" is missing in C# tests.json file", className)); - } + Assert.AreEqual(discoveredTestsJson, ReadTestsJson()); } /// /// Gets list of all test classes obtained by inspecting all the test assemblies. /// - private List DiscoverAllTestClasses() + private Dictionary> DiscoverAllTestClasses() { var assemblies = GetTestAssemblies(); - var testClasses = new List(); + var testsByAssembly = new Dictionary>(); foreach (var assembly in assemblies) { + var testClasses = new List(); foreach (var t in assembly.GetTypes()) { foreach (var m in t.GetMethods()) @@ -89,16 +86,19 @@ namespace Grpc.Core.Tests } } + testClasses.Sort(); + testsByAssembly.Add(assembly.GetName().Name, testClasses); } - testClasses.Sort(); - return testClasses; + return testsByAssembly; } - private string GetTestsJson() + /// + /// Reads contents of tests.json file. + /// + private string ReadTestsJson() { var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tests.json"); - return File.ReadAllText(testsJsonFile); } diff --git a/src/csharp/tests.json b/src/csharp/tests.json index 718bfa3287b..f733352a310 100644 --- a/src/csharp/tests.json +++ b/src/csharp/tests.json @@ -1,11 +1,5 @@ { - "assemblies": [ - "Grpc.Core.Tests", - "Grpc.Examples.Tests", - "Grpc.HealthCheck.Tests", - "Grpc.IntegrationTesting" - ], - "tests": [ + "Grpc.Core.Tests": [ "Grpc.Core.Internal.Tests.AsyncCallTest", "Grpc.Core.Internal.Tests.ChannelArgsSafeHandleTest", "Grpc.Core.Internal.Tests.CompletionQueueEventTest", @@ -32,13 +26,19 @@ "Grpc.Core.Tests.ServerTest", "Grpc.Core.Tests.ShutdownTest", "Grpc.Core.Tests.TimeoutsTest", - "Grpc.Core.Tests.UserAgentStringTest", - "Math.Tests.MathClientServerTest", + "Grpc.Core.Tests.UserAgentStringTest" + ], + "Grpc.Examples.Tests": [ + "Math.Tests.MathClientServerTest" + ], + "Grpc.HealthCheck.Tests": [ "Grpc.HealthCheck.Tests.HealthClientServerTest", - "Grpc.HealthCheck.Tests.HealthServiceImplTest", - "Grpc.IntegrationTesting.HistogramTest", + "Grpc.HealthCheck.Tests.HealthServiceImplTest" + ], + "Grpc.IntegrationTesting": [ "Grpc.IntegrationTesting.GeneratedClientTest", "Grpc.IntegrationTesting.GeneratedServiceBaseTest", + "Grpc.IntegrationTesting.HistogramTest", "Grpc.IntegrationTesting.InteropClientServerTest", "Grpc.IntegrationTesting.MetadataCredentialsTest", "Grpc.IntegrationTesting.RunnerClientServerTest", From 35e608fb8f203fcff668e9b915521beece49906e Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 16:35:06 -0700 Subject: [PATCH 16/21] run_tests.py script fixup --- tools/run_tests/run_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index e2cc3bdfffb..52244977035 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -522,7 +522,8 @@ class CSharpLanguage(object): else: cmdline = runtime_cmd + [assembly_file] + nunit_args - specs.append(self.config.job_spec([script_name] + extra_args, None, + specs.append(self.config.job_spec(cmdline, + None, shortname='csharp.coverage.%s' % assembly, environ=_FORCE_ENVIRON_FOR_WRAPPERS)) return specs From 67306daaa20fc1fda9c91ffc4573d69749ca80c1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 16:52:38 -0700 Subject: [PATCH 17/21] fix .bat script --- tools/run_tests/post_tests_csharp.bat | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/run_tests/post_tests_csharp.bat b/tools/run_tests/post_tests_csharp.bat index a3137aafa1f..7851b9137ac 100644 --- a/tools/run_tests/post_tests_csharp.bat +++ b/tools/run_tests/post_tests_csharp.bat @@ -2,6 +2,10 @@ setlocal +if not "%CONFIG%" == "gcov" ( + goto :EOF +) + @rem enter src/csharp directory cd /d %~dp0\..\..\src\csharp From bd58f6f76bedbf3ef4e875ab5fcebbcea71412de Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 9 Apr 2016 16:57:55 -0700 Subject: [PATCH 18/21] fix C# coverage on windows --- tools/run_tests/run_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 52244977035..d1beaa3e50d 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -512,13 +512,13 @@ class CSharpLanguage(object): # for test coverage, run all tests from the same assembly at once # on Windows, things get more complicated as we need to run the code coverage tool if self.platform == 'windows': - cmdline = ['packages\OpenCover.4.6.519\tools\OpenCover.Console.exe', + cmdline = ['src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe', '-target:%s' % assembly_file, '-targetdir:src\\csharp', '-targetargs:%s' % ' '.join(nunit_args), '-filter:+[Grpc.Core]*', '-register:user', - '-output:coverage_csharp_%s.xml' % assembly] + '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly] else: cmdline = runtime_cmd + [assembly_file] + nunit_args From a5f1f120aad8964bbcc198025bbaa4f2dd2094fd Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 11 Apr 2016 15:49:56 -0700 Subject: [PATCH 19/21] make sure OpenCover.Console runs exclusively --- tools/run_tests/run_tests.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index d1beaa3e50d..9dff686bbf6 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -500,7 +500,7 @@ class CSharpLanguage(object): specs = [] for assembly in tests_by_assembly.iterkeys(): assembly_file = 'src/csharp/%s/bin/%s/%s.exe' % (assembly, msbuild_config, assembly) - if self.config.build_config != 'gcov': + if self.config.build_config != 'gcov' or self.platform != 'windows': # normally, run each test as a separate process for test in tests_by_assembly[assembly]: cmdline = runtime_cmd + [assembly_file, '--test=%s' % test] + nunit_args @@ -509,22 +509,23 @@ class CSharpLanguage(object): shortname='csharp.%s' % test, environ=_FORCE_ENVIRON_FOR_WRAPPERS)) else: - # for test coverage, run all tests from the same assembly at once - # on Windows, things get more complicated as we need to run the code coverage tool - if self.platform == 'windows': - cmdline = ['src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe', - '-target:%s' % assembly_file, - '-targetdir:src\\csharp', - '-targetargs:%s' % ' '.join(nunit_args), - '-filter:+[Grpc.Core]*', - '-register:user', - '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly] - else: - cmdline = runtime_cmd + [assembly_file] + nunit_args - + # For C# test coverage, run all tests from the same assembly at once + # using OpenCover.Console (only works on Windows). + cmdline = ['src\\csharp\\packages\\OpenCover.4.6.519\\tools\\OpenCover.Console.exe', + '-target:%s' % assembly_file, + '-targetdir:src\\csharp', + '-targetargs:%s' % ' '.join(nunit_args), + '-filter:+[Grpc.Core]*', + '-register:user', + '-output:src\\csharp\\coverage_csharp_%s.xml' % assembly] + + # set really high cpu_cost to make sure instances of OpenCover.Console run exclusively + # to prevent problems with registering the profiler. + run_exclusive = 1000000 specs.append(self.config.job_spec(cmdline, None, shortname='csharp.coverage.%s' % assembly, + cpu_cost=run_exclusive, environ=_FORCE_ENVIRON_FOR_WRAPPERS)) return specs From d550ad1f7cd9cbd704a126873b2530e16fc7f3d9 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 11 Apr 2016 17:43:47 -0700 Subject: [PATCH 20/21] Add TextWriterLogger --- src/csharp/Grpc.Core/Grpc.Core.csproj | 5 +- src/csharp/Grpc.Core/Logging/ConsoleLogger.cs | 97 +--------- .../Grpc.Core/Logging/TextWriterLogger.cs | 176 ++++++++++++++++++ 3 files changed, 182 insertions(+), 96 deletions(-) create mode 100644 src/csharp/Grpc.Core/Logging/TextWriterLogger.cs diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 251a6889464..95077a6ca5a 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -58,6 +58,7 @@ + @@ -140,9 +141,7 @@
- - - + Resources\roots.pem diff --git a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs index da74e55a95f..5e8dced6414 100644 --- a/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs +++ b/src/csharp/Grpc.Core/Logging/ConsoleLogger.cs @@ -38,117 +38,28 @@ using System.Globalization; namespace Grpc.Core.Logging { /// Logger that logs to System.Console. - public class ConsoleLogger : ILogger + public class ConsoleLogger : TextWriterLogger { - // Format similar enough to C core log format except nanosecond precision is not supported. - const string DateTimeFormatString = "MMdd HH:mm:ss.ffffff"; - - readonly Type forType; - readonly string forTypeString; - /// Creates a console logger not associated to any specific type. public ConsoleLogger() : this(null) { } /// Creates a console logger that logs messsage specific for given type. - private ConsoleLogger(Type forType) + private ConsoleLogger(Type forType) : base(() => Console.Error, forType) { - this.forType = forType; - if (forType != null) - { - var namespaceStr = forType.Namespace ?? ""; - if (namespaceStr.Length > 0) - { - namespaceStr += "."; - } - this.forTypeString = namespaceStr + forType.Name + " "; - } - else - { - this.forTypeString = ""; - } } /// /// Returns a logger associated with the specified type. /// - public ILogger ForType() + public override ILogger ForType() { - if (typeof(T) == forType) + if (typeof(T) == AssociatedType) { return this; } return new ConsoleLogger(typeof(T)); } - - /// Logs a message with severity Debug. - public void Debug(string message) - { - Log("D", message); - } - - /// Logs a formatted message with severity Debug. - public void Debug(string format, params object[] formatArgs) - { - Debug(string.Format(format, formatArgs)); - } - - /// Logs a message with severity Info. - public void Info(string message) - { - Log("I", message); - } - - /// Logs a formatted message with severity Info. - public void Info(string format, params object[] formatArgs) - { - Info(string.Format(format, formatArgs)); - } - - /// Logs a message with severity Warning. - public void Warning(string message) - { - Log("W", message); - } - - /// Logs a formatted message with severity Warning. - public void Warning(string format, params object[] formatArgs) - { - Warning(string.Format(format, formatArgs)); - } - - /// Logs a message and an associated exception with severity Warning. - public void Warning(Exception exception, string message) - { - Warning(message + " " + exception); - } - - /// Logs a message with severity Error. - public void Error(string message) - { - Log("E", message); - } - - /// Logs a formatted message with severity Error. - public void Error(string format, params object[] formatArgs) - { - Error(string.Format(format, formatArgs)); - } - - /// Logs a message and an associated exception with severity Error. - public void Error(Exception exception, string message) - { - Error(message + " " + exception); - } - - private void Log(string severityString, string message) - { - Console.Error.WriteLine("{0}{1} {2}{3}", - severityString, - DateTime.Now.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), - forTypeString, - message); - } } } diff --git a/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs b/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs new file mode 100644 index 00000000000..397320ddffa --- /dev/null +++ b/src/csharp/Grpc.Core/Logging/TextWriterLogger.cs @@ -0,0 +1,176 @@ +#region Copyright notice and license + +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using Grpc.Core.Utils; + +namespace Grpc.Core.Logging +{ + /// Logger that logs to an arbitrary System.IO.TextWriter. + public class TextWriterLogger : ILogger + { + // Format similar enough to C core log format except nanosecond precision is not supported. + const string DateTimeFormatString = "MMdd HH:mm:ss.ffffff"; + + readonly Func textWriterProvider; + readonly Type forType; + readonly string forTypeString; + + /// + /// Creates a console logger not associated to any specific type and writes to given System.IO.TextWriter. + /// User is responsible for providing an instance of TextWriter that is thread-safe. + /// + public TextWriterLogger(TextWriter textWriter) : this(() => textWriter) + { + GrpcPreconditions.CheckNotNull(textWriter); + } + + /// + /// Creates a console logger not associated to any specific type and writes to a System.IO.TextWriter obtained from given provider. + /// User is responsible for providing an instance of TextWriter that is thread-safe. + /// + public TextWriterLogger(Func textWriterProvider) : this(textWriterProvider, null) + { + } + + /// Creates a console logger that logs messsage specific for given type. + protected TextWriterLogger(Func textWriterProvider, Type forType) + { + this.textWriterProvider = GrpcPreconditions.CheckNotNull(textWriterProvider); + this.forType = forType; + if (forType != null) + { + var namespaceStr = forType.Namespace ?? ""; + if (namespaceStr.Length > 0) + { + namespaceStr += "."; + } + this.forTypeString = namespaceStr + forType.Name + " "; + } + else + { + this.forTypeString = ""; + } + } + + /// + /// Returns a logger associated with the specified type. + /// + public virtual ILogger ForType() + { + if (typeof(T) == forType) + { + return this; + } + return new TextWriterLogger(this.textWriterProvider, typeof(T)); + } + + /// Logs a message with severity Debug. + public void Debug(string message) + { + Log("D", message); + } + + /// Logs a formatted message with severity Debug. + public void Debug(string format, params object[] formatArgs) + { + Debug(string.Format(format, formatArgs)); + } + + /// Logs a message with severity Info. + public void Info(string message) + { + Log("I", message); + } + + /// Logs a formatted message with severity Info. + public void Info(string format, params object[] formatArgs) + { + Info(string.Format(format, formatArgs)); + } + + /// Logs a message with severity Warning. + public void Warning(string message) + { + Log("W", message); + } + + /// Logs a formatted message with severity Warning. + public void Warning(string format, params object[] formatArgs) + { + Warning(string.Format(format, formatArgs)); + } + + /// Logs a message and an associated exception with severity Warning. + public void Warning(Exception exception, string message) + { + Warning(message + " " + exception); + } + + /// Logs a message with severity Error. + public void Error(string message) + { + Log("E", message); + } + + /// Logs a formatted message with severity Error. + public void Error(string format, params object[] formatArgs) + { + Error(string.Format(format, formatArgs)); + } + + /// Logs a message and an associated exception with severity Error. + public void Error(Exception exception, string message) + { + Error(message + " " + exception); + } + + /// Gets the type associated with this logger. + protected Type AssociatedType + { + get { return forType; } + } + + private void Log(string severityString, string message) + { + textWriterProvider().WriteLine("{0}{1} {2}{3}", + severityString, + DateTime.Now.ToString(DateTimeFormatString, CultureInfo.InvariantCulture), + forTypeString, + message); + } + } +} From 2f0519e9be3a280483a93d297811882e1e4232b0 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 11 Apr 2016 17:52:43 -0700 Subject: [PATCH 21/21] work around nunit issue #1406 --- src/csharp/Grpc.Core.Tests/NUnitMain.cs | 4 ++++ src/csharp/Grpc.Examples.Tests/NUnitMain.cs | 4 ++++ src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs | 4 ++++ src/csharp/Grpc.IntegrationTesting/NUnitMain.cs | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/csharp/Grpc.Core.Tests/NUnitMain.cs b/src/csharp/Grpc.Core.Tests/NUnitMain.cs index 13e5b27f7bd..9c1d7bf3c8a 100644 --- a/src/csharp/Grpc.Core.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.Core.Tests/NUnitMain.cs @@ -33,6 +33,8 @@ using System; using System.Reflection; +using Grpc.Core; +using Grpc.Core.Logging; using NUnit.Common; using NUnitLite; @@ -45,6 +47,8 @@ namespace Grpc.Core.Tests { public static int Main(string[] args) { + // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406. + GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error)); #if DOTNET5_4 return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else diff --git a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs index e6b76bcf3ba..ea87802766b 100644 --- a/src/csharp/Grpc.Examples.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.Examples.Tests/NUnitMain.cs @@ -33,6 +33,8 @@ using System; using System.Reflection; +using Grpc.Core; +using Grpc.Core.Logging; using NUnit.Common; using NUnitLite; @@ -45,6 +47,8 @@ namespace Grpc.Examples.Tests { public static int Main(string[] args) { + // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406. + GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error)); #if DOTNET5_4 return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else diff --git a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs index 6d77b12fef9..0820523f35c 100644 --- a/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.HealthCheck.Tests/NUnitMain.cs @@ -33,6 +33,8 @@ using System; using System.Reflection; +using Grpc.Core; +using Grpc.Core.Logging; using NUnit.Common; using NUnitLite; @@ -45,6 +47,8 @@ namespace Grpc.HealthCheck.Tests { public static int Main(string[] args) { + // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406. + GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error)); #if DOTNET5_4 return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else diff --git a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs index 4db8e158d3c..d8902de08f5 100644 --- a/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs +++ b/src/csharp/Grpc.IntegrationTesting/NUnitMain.cs @@ -33,6 +33,8 @@ using System; using System.Reflection; +using Grpc.Core; +using Grpc.Core.Logging; using NUnit.Common; using NUnitLite; @@ -45,6 +47,8 @@ namespace Grpc.IntegrationTesting { public static int Main(string[] args) { + // Make logger immune to NUnit capturing stdout and stderr to workaround https://github.com/nunit/nunit/issues/1406. + GrpcEnvironment.SetLogger(new TextWriterLogger(Console.Error)); #if DOTNET5_4 return new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args, new ExtendedTextWrapper(Console.Out), Console.In); #else