Skip to content

Commit f68f5b0

Browse files
authored
Fix HTTP/2 tests that use HttpClient and H2C (#24981)
1 parent 592cea6 commit f68f5b0

File tree

6 files changed

+77
-66
lines changed

6 files changed

+77
-66
lines changed

src/Grpc/test/InteropTests/InteropTests.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public InteropTests(ITestOutputHelper output)
2525
_output = output;
2626
}
2727

28-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
28+
[Fact]
2929
public Task EmptyUnary() => InteropTestCase("empty_unary");
3030

3131
[Fact]
@@ -36,20 +36,20 @@ public InteropTests(ITestOutputHelper output)
3636
[QuarantinedTest]
3737
public Task ClientStreaming() => InteropTestCase("client_streaming");
3838

39-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
39+
[Fact]
4040
public Task ServerStreaming() => InteropTestCase("server_streaming");
4141

4242
[Fact]
4343
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/22101")]
4444
public Task PingPong() => InteropTestCase("ping_pong");
4545

46-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
46+
[Fact]
4747
public Task EmptyStream() => InteropTestCase("empty_stream");
4848

4949
[Fact]
5050
public Task CancelAfterBegin() => InteropTestCase("cancel_after_begin");
5151

52-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
52+
[Fact]
5353
public Task CancelAfterFirstResponse() => InteropTestCase("cancel_after_first_response");
5454

5555
[Fact]
@@ -59,30 +59,31 @@ public InteropTests(ITestOutputHelper output)
5959
[QuarantinedTest]
6060
public Task CustomMetadata() => InteropTestCase("custom_metadata");
6161

62-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
62+
[Fact]
6363
public Task StatusCodeAndMessage() => InteropTestCase("status_code_and_message");
6464

65-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
65+
[Fact]
6666
public Task SpecialStatusMessage() => InteropTestCase("special_status_message");
6767

68-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
68+
[Fact]
6969
public Task UnimplementedService() => InteropTestCase("unimplemented_service");
7070

71-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
71+
[Fact]
7272
public Task UnimplementedMethod() => InteropTestCase("unimplemented_method");
7373

7474
[Fact]
75-
[QuarantinedTest]
75+
[QuarantinedTest("Server is getting 'identity' encoding. Will resolve in gRPC project when updated SDK is available.")]
7676
public Task ClientCompressedUnary() => InteropTestCase("client_compressed_unary");
7777

78-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
78+
[Fact]
79+
[QuarantinedTest("Server is getting 'identity' encoding. Will resolve in gRPC project when updated SDK is available.")]
7980
public Task ClientCompressedStreaming() => InteropTestCase("client_compressed_streaming");
8081

8182
[Fact]
8283
[QuarantinedTest]
8384
public Task ServerCompressedUnary() => InteropTestCase("server_compressed_unary");
8485

85-
[Fact(Skip= "https://github.com/dotnet/aspnetcore/issues/24902")]
86+
[Fact]
8687
public Task ServerCompressedStreaming() => InteropTestCase("server_compressed_streaming");
8788

8889
private async Task InteropTestCase(string name)

src/Grpc/test/testassets/InteropClient/InteropClient.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private InteropClient(ClientOptions options)
100100
{
101101
#pragma warning disable CS0618 // Type or member is obsolete
102102
loggerOptions.IncludeScopes = true;
103+
loggerOptions.DisableColors = true;
103104
#pragma warning restore CS0618 // Type or member is obsolete
104105
});
105106
});
@@ -167,7 +168,7 @@ private async Task<IChannelWrapper> HttpClientCreateChannel()
167168
httpClientHandler.ClientCertificates.Add(cert);
168169
}
169170

170-
var httpClient = new HttpClient(httpClientHandler);
171+
var httpClient = new HttpClient(new VersionPolicyHandler(httpClientHandler));
171172

172173
var channel = GrpcChannel.ForAddress($"{scheme}://{options.ServerHost}:{options.ServerPort}", new GrpcChannelOptions
173174
{
@@ -179,7 +180,20 @@ private async Task<IChannelWrapper> HttpClientCreateChannel()
179180
return new GrpcChannelWrapper(channel);
180181
}
181182

182-
private bool IsHttpClient() => string.Equals(options.ClientType, "httpclient", StringComparison.OrdinalIgnoreCase);
183+
// TODO(JamesNK): This type can be removed in the future when Grpc.Net.Client sets VersionPolicy automatically.
184+
// https://github.com/grpc/grpc-dotnet/pull/987
185+
private class VersionPolicyHandler : DelegatingHandler
186+
{
187+
public VersionPolicyHandler(HttpMessageHandler innerHandler) : base(innerHandler)
188+
{
189+
}
190+
191+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
192+
{
193+
request.VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
194+
return base.SendAsync(request, cancellationToken);
195+
}
196+
}
183197

184198
private async Task<ChannelCredentials> CreateCredentialsAsync(bool? useTestCaOverride = null)
185199
{

src/Grpc/test/testassets/InteropClient/RunTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Param
1+
Param
22
(
33
[bool]$use_tls = $false
44
)
@@ -50,4 +50,4 @@ foreach ($test in $allTests)
5050
Write-Host
5151
}
5252

53-
Write-Host "Done" -ForegroundColor Cyan
53+
Write-Host "Done" -ForegroundColor Cyan

src/Grpc/test/testassets/InteropWebsite/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
3737
Host.CreateDefaultBuilder(args)
3838
.ConfigureLogging(builder =>
3939
{
40-
builder.AddConsole();
40+
builder.AddConsole(loggerOptions =>
41+
{
42+
#pragma warning disable CS0618 // Type or member is obsolete
43+
loggerOptions.DisableColors = true;
44+
#pragma warning restore CS0618 // Type or member is obsolete
45+
});
4146
builder.SetMinimumLevel(LogLevel.Trace);
4247
})
4348
.ConfigureWebHostDefaults(webBuilder =>

src/Grpc/test/testassets/InteropWebsite/TestServiceImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private static void EnsureCompression(BoolValue? expectCompressed, ServerCallCon
135135
{
136136
// ServerCallContext.RequestHeaders filters out grpc-* headers
137137
// Get grpc-encoding from HttpContext instead
138-
var encoding = context.GetHttpContext().Request.Headers.SingleOrDefault(h => h.Key == "grpc-encoding").Value.SingleOrDefault();
138+
var encoding = context.GetHttpContext().Request.Headers.SingleOrDefault(h => string.Equals(h.Key, "grpc-encoding", StringComparison.OrdinalIgnoreCase)).Value.SingleOrDefault();
139139
if (expectCompressed.Value)
140140
{
141141
if (encoding == null || encoding == "identity")

0 commit comments

Comments
 (0)