Skip to content
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

Add WriteResponseHeadersAsync test #2452

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
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
31 changes: 30 additions & 1 deletion test/FunctionalTests/Client/UnaryTests.cs
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 Down Expand Up @@ -68,6 +68,35 @@ Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext context
StringAssert.StartsWith("Failed to deserialize response message.", call.GetStatus().Detail);
}

[Test]
public async Task WriteResponseHeadersAsync_HeadersSentEarly()
{
var tcs = new TaskCompletionSource<HelloReply>(TaskCreationOptions.RunContinuationsAsynchronously);

async Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext context)
{
await context.WriteResponseHeadersAsync(new Metadata
{
new Metadata.Entry("key", "value")
});

return await tcs.Task;
}

// Arrange
var method = Fixture.DynamicGrpc.AddUnaryMethod<HelloRequest, HelloReply>(UnaryThrowError);
var channel = CreateChannel();
var client = TestClientFactory.Create(channel, method);

// Act
var call = client.UnaryCall(new HelloRequest());

// Assert
var headers = await call.ResponseHeadersAsync.DefaultTimeout();
Assert.AreEqual("value", headers.GetValue("key"));
Assert.IsFalse(call.ResponseAsync.IsCompleted);
}
JamesNK marked this conversation as resolved.
Show resolved Hide resolved

[TestCase("fr", "fr")]
[TestCase(null, "en-US")]
public async Task Unary_SetAcceptLanguage_ServerCultureChanged(string clientAcceptLanguage, string expectedServerCulture)
Expand Down