Skip to content

Commit

Permalink
Fix race condition in passive health test
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Apr 10, 2024
1 parent 7d16457 commit 152ad1a
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
public async Task PassiveHealthChecksEnabled_MultipleDestinationFailures_ProxyReturnsServiceUnavailable()
{
var destinationReached = false;
IProxyStateLookup? lookup = null;

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build Ubuntu)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build Ubuntu)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build Ubuntu)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build macOS latest)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build macOS latest)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build macOS latest)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 55 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L55

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(55,26): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
string? clusterId = null;

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build Ubuntu)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build Ubuntu)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build macOS latest)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci (Build macOS latest)

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check failure on line 56 in test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs

View check run for this annotation

Azure Pipelines / microsoft-reverse-proxy-ci

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs#L56

test/ReverseProxy.FunctionalTests/PassiveHealthCheckTests.cs(56,15): error CS8632: (NETCORE_ENGINEERING_TELEMETRY=Build) The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

var test = new TestEnvironment(
context =>
Expand All @@ -74,20 +76,51 @@ public async Task PassiveHealthChecksEnabled_MultipleDestinationFailures_ProxyRe
}
};
clusterId = c.ClusterId;
return (c, r);
},
ConfigureProxy = proxyBuilder => proxyBuilder.Services.AddSingleton<IForwarderHttpClientFactory>(new MockHttpClientFactory((_, _) => throw new IOException())),
ConfigureProxyApp = proxyApp =>
{
lookup = proxyApp.ApplicationServices.GetRequiredService<IProxyStateLookup>();
},
};

await test.Invoke(async uri =>
{
using var client = new HttpClient();
for (var i = 0; i < 42; i++)
for (var i = 0; i < 10; i++)
{
using var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));
Assert.Equal(HttpStatusCode.BadGateway, response.StatusCode);
}
Assert.NotNull(lookup);
Assert.NotNull(clusterId);
// The destination list will be updated asynchronously in the background.
// Wait until that update takes effect.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
while (true)
{
Assert.True(lookup.TryGetCluster(clusterId, out var cluster));
Assert.Single(cluster.DestinationsState.AllDestinations);
Assert.Equal(i < 10 ? HttpStatusCode.BadGateway : HttpStatusCode.ServiceUnavailable, response.StatusCode);
await Task.Yield();
if (cluster.DestinationsState.AvailableDestinations.Count == 0)
{
break;
}
await Task.Delay(10, cts.Token);
}
for (var i = 0; i < 42; i++)
{
using var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, uri));
Assert.Equal(HttpStatusCode.ServiceUnavailable, response.StatusCode);
}
});

Expand Down

0 comments on commit 152ad1a

Please sign in to comment.