Skip to content

Commit 1f5186e

Browse files
authored
Fix warnings when running benchmarks in .NET 7 (#1749)
1 parent 4b10c6c commit 1f5186e

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

perf/benchmarkapps/GrpcAspNetCoreServer/GrpcAspNetCoreServer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<!-- Turn on preview features so we can use Http3. Can be removed in .NET 7 -->
1515
<EnablePreviewFeatures>True</EnablePreviewFeatures>
16+
<!-- TODO(JamesNK): Workaround https://github.com/grpc/grpc/issues/29672 -->
17+
<NoWarn>$(NoWarn);CS8981</NoWarn>
1618
</PropertyGroup>
1719

1820
<ItemGroup>

perf/benchmarkapps/GrpcClient/GrpcClient.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<DefineConstants Condition="'$(EnableGrpcWeb)' == 'true'">$(DefineConstants);GRPC_WEB</DefineConstants>
77
<!-- Enable server GC to more closely simulate a microservice app making calls -->
88
<ServerGarbageCollection>true</ServerGarbageCollection>
9+
<!-- TODO(JamesNK): Workaround https://github.com/grpc/grpc/issues/29672 -->
10+
<NoWarn>$(NoWarn);CS8981</NoWarn>
911
</PropertyGroup>
1012

1113
<ItemGroup>

perf/benchmarkapps/GrpcCoreServer/GrpcCoreServer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<OutputType>Exe</OutputType>
6+
<!-- TODO(JamesNK): Workaround https://github.com/grpc/grpc/issues/29672 -->
7+
<NoWarn>$(NoWarn);CS8981</NoWarn>
68
</PropertyGroup>
79

810
<ItemGroup>

test/FunctionalTests/Web/Client/ServerStreamingMethodTests.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,34 +125,52 @@ public async Task SendValidRequest_ServerAbort_ClientThrowsAbortException()
125125
AssertHasLogRpcConnectionError(StatusCode.Aborted, "Aborted from server side.");
126126
}
127127

128-
[Test]
129-
public async Task SendValidRequest_ClientAbort_ClientThrowsCancelledException()
128+
[TestCase(true)]
129+
[TestCase(false)]
130+
public async Task SendValidRequest_ClientAbort_ClientThrowsCancelledException(bool delayWithCancellationToken)
130131
{
131132
var serverAbortedTcs = new TaskCompletionSource<object?>(TaskCreationOptions.RunContinuationsAsynchronously);
132133
async Task ServerStreamingEcho(ServerStreamingEchoRequest request, IServerStreamWriter<ServerStreamingEchoResponse> responseStream, ServerCallContext context)
133134
{
134135
Logger.LogInformation("Server call started");
135136

136137
var httpContext = context.GetHttpContext();
137-
httpContext.RequestAborted.Register(() => serverAbortedTcs.SetResult(null));
138+
httpContext.RequestAborted.Register(() =>
139+
{
140+
Logger.LogInformation("Server RequestAborted raised.");
141+
serverAbortedTcs.SetResult(null);
142+
});
138143

139-
for (var i = 0; i < request.MessageCount; i++)
144+
try
140145
{
141-
try
146+
for (var i = 0; i < request.MessageCount; i++)
142147
{
143148
Logger.LogInformation($"Server writing message {i}");
144149
await responseStream.WriteAsync(new ServerStreamingEchoResponse
145150
{
146151
Message = request.Message
147152
});
148153

149-
await Task.Delay(request.MessageInterval.ToTimeSpan(), context.CancellationToken);
150-
}
151-
catch (OperationCanceledException)
152-
{
153-
return;
154+
if (delayWithCancellationToken)
155+
{
156+
await Task.Delay(request.MessageInterval.ToTimeSpan(), context.CancellationToken);
157+
}
158+
else
159+
{
160+
await Task.Delay(request.MessageInterval.ToTimeSpan());
161+
}
154162
}
155163
}
164+
catch (Exception ex)
165+
{
166+
Logger.LogInformation(ex, "Server error.");
167+
return;
168+
}
169+
finally
170+
{
171+
Logger.LogInformation("Server waiting for RequestAborted.");
172+
await serverAbortedTcs.Task;
173+
}
156174
}
157175

158176
// Arrage
@@ -201,6 +219,7 @@ await responseStream.WriteAsync(new ServerStreamingEchoResponse
201219
if (EndpointName != TestServerEndpointName.Http1)
202220
{
203221
// Verify the abort reached the server.
222+
Logger.LogInformation("Client waiting for notification of abort in server.");
204223
await serverAbortedTcs.Task.DefaultTimeout();
205224
}
206225
}

0 commit comments

Comments
 (0)