Skip to content
Snippets Groups Projects
Commit a4291e70 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

fixing tests

parent 5b0b392c
Branches
Tags
No related merge requests found
...@@ -48,14 +48,17 @@ namespace Grpc.Core.Tests ...@@ -48,14 +48,17 @@ namespace Grpc.Core.Tests
/// </summary> /// </summary>
public class TimeoutsTest public class TimeoutsTest
{ {
MockServiceHelper helper = new MockServiceHelper(); MockServiceHelper helper;
Server server; Server server;
Channel channel; Channel channel;
[SetUp] [SetUp]
public void Init() public void Init()
{ {
helper = new MockServiceHelper();
server = helper.GetServer(); server = helper.GetServer();
server.Start();
channel = helper.GetChannel(); channel = helper.GetChannel();
} }
...@@ -145,6 +148,7 @@ namespace Grpc.Core.Tests ...@@ -145,6 +148,7 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void ServerReceivesCancellationOnTimeout() public void ServerReceivesCancellationOnTimeout()
{ {
object myLock = new object();
string receivedCancellation = "NO"; string receivedCancellation = "NO";
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => { helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => {
...@@ -152,7 +156,10 @@ namespace Grpc.Core.Tests ...@@ -152,7 +156,10 @@ namespace Grpc.Core.Tests
var tcs = new TaskCompletionSource<object>(); var tcs = new TaskCompletionSource<object>();
context.CancellationToken.Register(() => { tcs.SetResult(null); }); context.CancellationToken.Register(() => { tcs.SetResult(null); });
await tcs.Task; await tcs.Task;
receivedCancellation = "YES"; lock (myLock)
{
receivedCancellation = "YES";
}
return ""; return "";
}); });
...@@ -166,7 +173,11 @@ namespace Grpc.Core.Tests ...@@ -166,7 +173,11 @@ namespace Grpc.Core.Tests
// We can't guarantee the status code is always DeadlineExceeded. See issue #2685. // We can't guarantee the status code is always DeadlineExceeded. See issue #2685.
Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal });
} }
Assert.AreEqual("YES", receivedCancellation);
lock (myLock)
{
Assert.AreEqual("YES", receivedCancellation);
}
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment