Skip to content

Commit 490894c

Browse files
authored
Cleanup gRPC unit testing helpers in tester sample (grpc#2548)
1 parent df3d8dc commit 490894c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

examples/Tester/Tests/Server/UnitTests/Helpers/TestServerCallContext.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -22,8 +22,6 @@
2222
using System.Threading.Tasks;
2323
using Grpc.Core;
2424

25-
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
26-
#pragma warning disable CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
2725
namespace Tests.Server.UnitTests.Helpers
2826
{
2927
public class TestServerCallContext : ServerCallContext
@@ -81,4 +79,3 @@ public static TestServerCallContext Create(Metadata? requestHeaders = null, Canc
8179
}
8280
}
8381
}
84-
#pragma warning restore CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).

examples/Tester/Tests/Server/UnitTests/Helpers/TestServerStreamWriter.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -22,8 +22,6 @@
2222
using System.Threading.Tasks;
2323
using Grpc.Core;
2424

25-
// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
26-
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
2725
namespace Tests.Server.UnitTests.Helpers
2826
{
2927
public class TestServerStreamWriter<T> : IServerStreamWriter<T> where T : class
@@ -63,8 +61,12 @@ public IAsyncEnumerable<T> ReadAllAsync()
6361
}
6462
}
6563

66-
public Task WriteAsync(T message)
64+
public Task WriteAsync(T message, CancellationToken cancellationToken)
6765
{
66+
if (cancellationToken.IsCancellationRequested)
67+
{
68+
return Task.FromCanceled(cancellationToken);
69+
}
6870
if (_serverCallContext.CancellationToken.IsCancellationRequested)
6971
{
7072
return Task.FromCanceled(_serverCallContext.CancellationToken);
@@ -77,6 +79,10 @@ public Task WriteAsync(T message)
7779

7880
return Task.CompletedTask;
7981
}
82+
83+
public Task WriteAsync(T message)
84+
{
85+
return WriteAsync(message, CancellationToken.None);
86+
}
8087
}
8188
}
82-
#pragma warning restore CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).

0 commit comments

Comments
 (0)