From a4291e7073a40777bfe8845bd926612a76e154f6 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 7 Aug 2015 19:13:31 -0700 Subject: [PATCH] fixing tests --- src/csharp/Grpc.Core.Tests/TimeoutsTest.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs index 239fc95cb6a..51709813bf8 100644 --- a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs +++ b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs @@ -48,14 +48,17 @@ namespace Grpc.Core.Tests /// public class TimeoutsTest { - MockServiceHelper helper = new MockServiceHelper(); + MockServiceHelper helper; Server server; Channel channel; [SetUp] public void Init() { + helper = new MockServiceHelper(); + server = helper.GetServer(); + server.Start(); channel = helper.GetChannel(); } @@ -145,6 +148,7 @@ namespace Grpc.Core.Tests [Test] public void ServerReceivesCancellationOnTimeout() { + object myLock = new object(); string receivedCancellation = "NO"; helper.UnaryHandler = new UnaryServerMethod(async (request, context) => { @@ -152,7 +156,10 @@ namespace Grpc.Core.Tests var tcs = new TaskCompletionSource(); context.CancellationToken.Register(() => { tcs.SetResult(null); }); await tcs.Task; - receivedCancellation = "YES"; + lock (myLock) + { + receivedCancellation = "YES"; + } return ""; }); @@ -166,7 +173,11 @@ namespace Grpc.Core.Tests // We can't guarantee the status code is always DeadlineExceeded. See issue #2685. Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); } - Assert.AreEqual("YES", receivedCancellation); + + lock (myLock) + { + Assert.AreEqual("YES", receivedCancellation); + } } } }