Skip to content

Commit

Permalink
Cleanup gRPC unit testing helpers in tester sample (#2548)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Oct 2, 2024
1 parent df3d8dc commit 490894c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -22,8 +22,6 @@
using System.Threading.Tasks;
using Grpc.Core;

// TODO(JamesNK): Remove nullable override after Grpc.Core.Api update
#pragma warning disable CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
namespace Tests.Server.UnitTests.Helpers
{
public class TestServerCallContext : ServerCallContext
Expand Down Expand Up @@ -81,4 +79,3 @@ public static TestServerCallContext Create(Metadata? requestHeaders = null, Canc
}
}
}
#pragma warning restore CS8764 // Nullability of return type doesn't match overridden member (possibly because of nullability attributes).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -22,8 +22,6 @@
using System.Threading.Tasks;
using Grpc.Core;

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

public Task WriteAsync(T message)
public Task WriteAsync(T message, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled(cancellationToken);
}
if (_serverCallContext.CancellationToken.IsCancellationRequested)
{
return Task.FromCanceled(_serverCallContext.CancellationToken);
Expand All @@ -77,6 +79,10 @@ public Task WriteAsync(T message)

return Task.CompletedTask;
}

public Task WriteAsync(T message)
{
return WriteAsync(message, CancellationToken.None);
}
}
}
#pragma warning restore CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).

0 comments on commit 490894c

Please sign in to comment.