Skip to content

Fix HTTP/2 tests that use HttpClient and H2C #24981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/Grpc/test/InteropTests/InteropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public InteropTests(ITestOutputHelper output)
_output = output;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[Fact]
[QuarantinedTest]
public Task ServerCompressedUnary() => InteropTestCase("server_compressed_unary");

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

private async Task InteropTestCase(string name)
Expand Down
18 changes: 16 additions & 2 deletions src/Grpc/test/testassets/InteropClient/InteropClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private InteropClient(ClientOptions options)
{
#pragma warning disable CS0618 // Type or member is obsolete
loggerOptions.IncludeScopes = true;
loggerOptions.DisableColors = true;
#pragma warning restore CS0618 // Type or member is obsolete
});
});
Expand Down Expand Up @@ -167,7 +168,7 @@ private async Task<IChannelWrapper> HttpClientCreateChannel()
httpClientHandler.ClientCertificates.Add(cert);
}

var httpClient = new HttpClient(httpClientHandler);
var httpClient = new HttpClient(new VersionPolicyHandler(httpClientHandler));

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

private bool IsHttpClient() => string.Equals(options.ClientType, "httpclient", StringComparison.OrdinalIgnoreCase);
// TODO(JamesNK): This type can be removed in the future when Grpc.Net.Client sets VersionPolicy automatically.
// https://github.com/grpc/grpc-dotnet/pull/987
private class VersionPolicyHandler : DelegatingHandler
{
public VersionPolicyHandler(HttpMessageHandler innerHandler) : base(innerHandler)
{
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You plan on using Exact in gRPC, no?

Suggested change
request.VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically gRPC should work with HTTP/3 so OrHigher seems like the best choice.

return base.SendAsync(request, cancellationToken);
}
}

private async Task<ChannelCredentials> CreateCredentialsAsync(bool? useTestCaOverride = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc/test/testassets/InteropClient/RunTests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Param
Param
(
[bool]$use_tls = $false
)
Expand Down Expand Up @@ -50,4 +50,4 @@ foreach ($test in $allTests)
Write-Host
}

Write-Host "Done" -ForegroundColor Cyan
Write-Host "Done" -ForegroundColor Cyan
7 changes: 6 additions & 1 deletion src/Grpc/test/testassets/InteropWebsite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging(builder =>
{
builder.AddConsole();
builder.AddConsole(loggerOptions =>
{
#pragma warning disable CS0618 // Type or member is obsolete
loggerOptions.DisableColors = true;
#pragma warning restore CS0618 // Type or member is obsolete
});
builder.SetMinimumLevel(LogLevel.Trace);
})
.ConfigureWebHostDefaults(webBuilder =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static void EnsureCompression(BoolValue? expectCompressed, ServerCallCon
{
// ServerCallContext.RequestHeaders filters out grpc-* headers
// Get grpc-encoding from HttpContext instead
var encoding = context.GetHttpContext().Request.Headers.SingleOrDefault(h => h.Key == "grpc-encoding").Value.SingleOrDefault();
var encoding = context.GetHttpContext().Request.Headers.SingleOrDefault(h => string.Equals(h.Key, "grpc-encoding", StringComparison.OrdinalIgnoreCase)).Value.SingleOrDefault();
if (expectCompressed.Value)
{
if (encoding == null || encoding == "identity")
Expand Down
Loading