Skip to content

Commit 434a5ba

Browse files
Add WriteResponseHeadersAsync test (#2452)
Co-authored-by: Brennan <brecon@microsoft.com>
1 parent 5e6821c commit 434a5ba

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/FunctionalTests/Client/UnaryTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext context
6868
StringAssert.StartsWith("Failed to deserialize response message.", call.GetStatus().Detail);
6969
}
7070

71+
[Test]
72+
public async Task WriteResponseHeadersAsync_HeadersSentEarly()
73+
{
74+
var tcs = new TaskCompletionSource<HelloReply>(TaskCreationOptions.RunContinuationsAsynchronously);
75+
76+
async Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext context)
77+
{
78+
await context.WriteResponseHeadersAsync(new Metadata
79+
{
80+
new Metadata.Entry("key", "value")
81+
});
82+
83+
return await tcs.Task;
84+
}
85+
86+
// Arrange
87+
var method = Fixture.DynamicGrpc.AddUnaryMethod<HelloRequest, HelloReply>(UnaryThrowError);
88+
var channel = CreateChannel();
89+
var client = TestClientFactory.Create(channel, method);
90+
91+
// Act
92+
var call = client.UnaryCall(new HelloRequest());
93+
94+
// Assert
95+
var headers = await call.ResponseHeadersAsync.DefaultTimeout();
96+
Assert.AreEqual("value", headers.GetValue("key"));
97+
Assert.IsFalse(call.ResponseAsync.IsCompleted);
98+
99+
tcs.SetResult(new HelloReply());
100+
}
101+
71102
[TestCase("fr", "fr")]
72103
[TestCase(null, "en-US")]
73104
public async Task Unary_SetAcceptLanguage_ServerCultureChanged(string clientAcceptLanguage, string expectedServerCulture)

0 commit comments

Comments
 (0)