Skip to content

Commit a1389a0

Browse files
authored
Fix error when HedgingDelay is null (#1351)
1 parent bf26e03 commit a1389a0

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/Grpc.Net.Client/Internal/GrpcMethodInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal static HedgingPolicyInfo CreateHedgingPolicy(HedgingPolicy h)
101101
{
102102
throw new InvalidOperationException("Hedging policy max attempts must be greater than 1.");
103103
}
104-
if (!(h.HedgingDelay >= TimeSpan.Zero))
104+
if (h.HedgingDelay != null && h.HedgingDelay < TimeSpan.Zero)
105105
{
106106
throw new InvalidOperationException("Hedging policy delay must be equal or greater than zero.");
107107
}

test/FunctionalTests/Client/HedgingTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ namespace Grpc.AspNetCore.FunctionalTests.Client
3939
[TestFixture]
4040
public class HedgingTests : FunctionalTestBase
4141
{
42+
[TestCase(null)]
4243
[TestCase(0)]
4344
[TestCase(20)]
44-
public async Task Unary_ExceedAttempts_Failure(int hedgingDelay)
45+
public async Task Unary_ExceedAttempts_Failure(int? hedgingDelay)
4546
{
4647
Task<DataMessage> UnaryFailure(DataMessage request, ServerCallContext context)
4748
{
@@ -57,7 +58,10 @@ Task<DataMessage> UnaryFailure(DataMessage request, ServerCallContext context)
5758
// Arrange
5859
var method = Fixture.DynamicGrpc.AddUnaryMethod<DataMessage, DataMessage>(UnaryFailure);
5960

60-
var channel = CreateChannel(serviceConfig: ServiceConfigHelpers.CreateHedgingServiceConfig(maxAttempts: 5, hedgingDelay: TimeSpan.FromMilliseconds(hedgingDelay)));
61+
var delay = (hedgingDelay == null)
62+
? (TimeSpan?)null
63+
: TimeSpan.FromMilliseconds(hedgingDelay.Value);
64+
var channel = CreateChannel(serviceConfig: ServiceConfigHelpers.CreateHedgingServiceConfig(maxAttempts: 5, hedgingDelay: delay));
6165

6266
var client = TestClientFactory.Create(channel, method);
6367

test/Shared/ServiceConfigHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static ServiceConfig CreateHedgingServiceConfig(
7676
var hedgingPolicy = new HedgingPolicy
7777
{
7878
MaxAttempts = maxAttempts ?? 5,
79-
HedgingDelay = hedgingDelay ?? TimeSpan.Zero
79+
HedgingDelay = hedgingDelay
8080
};
8181

8282
if (nonFatalStatusCodes != null)

0 commit comments

Comments
 (0)