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

Increase deadline precision offset #1604

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Feb 9, 2022

Timers and Datetime.UtcNow aren't precise. They can be wrong by up to 14ms on some OSes.

Increase deadline timer safety margin to 14ms. Prevents deadline timer being rescheduled, at the cost of a small delay in triggering deadline. Triggering deadline slightly later than the specified value is fine.

Making change because of flakey test

[TestCase(1)]
[TestCase(2)]
public async Task Unary_DeadlineExceedAfterServerCall_Failure(int exceptedServerCallCount)
{
var callCount = 0;
var tcs = new TaskCompletionSource<DataMessage>(TaskCreationOptions.RunContinuationsAsynchronously);
Task<DataMessage> UnaryFailure(DataMessage request, ServerCallContext context)
{
callCount++;
if (callCount < exceptedServerCallCount)
{
return Task.FromException<DataMessage>(new RpcException(new Status(StatusCode.DeadlineExceeded, "")));
}
return tcs.Task;
}
// Arrange
var method = Fixture.DynamicGrpc.AddUnaryMethod<DataMessage, DataMessage>(UnaryFailure);
var serviceConfig = ServiceConfigHelpers.CreateHedgingServiceConfig(nonFatalStatusCodes: new List<StatusCode> { StatusCode.DeadlineExceeded });
var channel = CreateChannel(serviceConfig: serviceConfig);
var client = TestClientFactory.Create(channel, method);
// Act
var call = client.UnaryCall(new DataMessage(), new CallOptions(deadline: DateTime.UtcNow.AddMilliseconds(200)));
// Assert
var ex = await ExceptionAssert.ThrowsAsync<RpcException>(() => call.ResponseAsync).DefaultTimeout();
Assert.AreEqual(StatusCode.DeadlineExceeded, ex.StatusCode);
Assert.AreEqual(StatusCode.DeadlineExceeded, call.GetStatus().StatusCode);
Assert.IsFalse(Logs.Any(l => l.EventId.Name == "DeadlineTimerRescheduled"));
}

@JamesNK JamesNK merged commit 11d7151 into grpc:master Feb 10, 2022
@JamesNK JamesNK deleted the jamesnk/deadline-precision branch February 10, 2022 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants