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

fixing tests

parent 0abb8474
No related branches found
No related tags found
No related merge requests found
...@@ -174,7 +174,7 @@ namespace Grpc.Core.Tests ...@@ -174,7 +174,7 @@ namespace Grpc.Core.Tests
} }
[Test] [Test]
public void AsyncUnaryCall_EchoMetadata() public async Task AsyncUnaryCall_EchoMetadata()
{ {
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) =>
{ {
...@@ -194,8 +194,7 @@ namespace Grpc.Core.Tests ...@@ -194,8 +194,7 @@ namespace Grpc.Core.Tests
new Metadata.Entry("binary-header-bin", new byte[] { 1, 2, 3, 0, 0xff }), new Metadata.Entry("binary-header-bin", new byte[] { 1, 2, 3, 0, 0xff }),
}; };
var call = Calls.AsyncUnaryCall(helper.CreateUnaryCall(new CallOptions(headers: headers)), "ABC"); var call = Calls.AsyncUnaryCall(helper.CreateUnaryCall(new CallOptions(headers: headers)), "ABC");
await call;
Assert.AreEqual("ABC", call.ResponseAsync.Result);
Assert.AreEqual(StatusCode.OK, call.GetStatus().StatusCode); Assert.AreEqual(StatusCode.OK, call.GetStatus().StatusCode);
...@@ -218,6 +217,10 @@ namespace Grpc.Core.Tests ...@@ -218,6 +217,10 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void UnaryCallPerformance() public void UnaryCallPerformance()
{ {
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => {
return request;
});
var callDetails = helper.CreateUnaryCall(); var callDetails = helper.CreateUnaryCall();
BenchmarkUtil.RunBenchmark(100, 100, BenchmarkUtil.RunBenchmark(100, 100,
() => { Calls.BlockingUnaryCall(callDetails, "ABC"); }); () => { Calls.BlockingUnaryCall(callDetails, "ABC"); });
......
...@@ -132,20 +132,16 @@ namespace Grpc.Core.Tests ...@@ -132,20 +132,16 @@ namespace Grpc.Core.Tests
} }
[Test] [Test]
public void ServerReceivesCancellationOnTimeout() public async Task ServerReceivesCancellationOnTimeout()
{ {
object myLock = new object(); var serverReceivedCancellationTcs = new TaskCompletionSource<bool>();
string receivedCancellation = "NO";
helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => { helper.UnaryHandler = new UnaryServerMethod<string, string>(async (request, context) => {
// wait until cancellation token is fired. // wait until cancellation token is fired.
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;
lock (myLock) serverReceivedCancellationTcs.SetResult(true);
{
receivedCancellation = "YES";
}
return ""; return "";
}); });
...@@ -153,10 +149,7 @@ namespace Grpc.Core.Tests ...@@ -153,10 +149,7 @@ namespace Grpc.Core.Tests
// We can't guarantee the status code always DeadlineExceeded. See issue #2685. // We can't guarantee the status code always DeadlineExceeded. See issue #2685.
Assert.Contains(ex.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); Assert.Contains(ex.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal });
lock (myLock) Assert.IsTrue(await serverReceivedCancellationTcs.Task);
{
Assert.AreEqual("YES", receivedCancellation);
}
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment