Skip to content
Merged
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
33 changes: 32 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,37 @@ 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);

tcs.SetResult(new HelloReply());
}

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