99using Microsoft . Extensions . Diagnostics . HealthChecks ;
1010using Polly . Retry ;
1111using Polly ;
12+ using k8s . Autorest ;
1213
1314[ assembly: AssemblyFixture ( typeof ( ReflectorIntegrationFixture ) ) ]
1415
@@ -21,6 +22,21 @@ public class HealthCheckIntegrationTests(ReflectorIntegrationFixture integration
2122 private readonly ReflectorIntegrationFixture _integrationFixture = integrationFixture ;
2223
2324
25+ private static readonly ResiliencePipeline < bool > HealthCheckResiliencePipeline =
26+ new ResiliencePipelineBuilder < bool > ( )
27+ . AddRetry ( new RetryStrategyOptions < bool >
28+ {
29+ ShouldHandle = new PredicateBuilder < bool > ( )
30+ . Handle < HttpOperationException > ( ex =>
31+ ex . Response . StatusCode == HttpStatusCode . NotFound )
32+ . HandleResult ( false ) ,
33+ MaxRetryAttempts = 10 ,
34+ Delay = TimeSpan . FromSeconds ( 1 )
35+ } )
36+ . AddTimeout ( TimeSpan . FromSeconds ( 30 ) )
37+ . Build ( ) ;
38+
39+
2440 [ Fact ]
2541 public async Task LivenessHealthCheck_Should_Return_Healthy ( )
2642 {
@@ -38,14 +54,17 @@ public async Task LivenessHealthCheck_Should_Return_Healthy()
3854 [ Fact ]
3955 public async Task ReadinessHealthCheck_Should_Return_Healthy ( )
4056 {
41- var httpClient = _integrationFixture . Reflector . CreateClient ( ) ;
4257 var settings = _integrationFixture . Reflector . Services . GetRequiredService < IgniteSettings > ( ) ;
43- var response = await httpClient . GetAsync ( settings . AspNetCore . HealthChecks . ReadinessEndpointPath ,
44- TestContext . Current . CancellationToken ) ;
45- var content = await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ;
58+ var httpClient = _integrationFixture . Reflector . CreateClient ( ) ;
4659
47- //Assert.Equal(HttpStatusCode.OK, response.StatusCode);
48- //Assert.Equal("text/plain", response.Content.Headers.ContentType?.MediaType);
49- Assert . Equal ( "Healthy" , content ) ;
60+ await HealthCheckResiliencePipeline . ExecuteAsync ( async token =>
61+ {
62+ var response = await httpClient . GetAsync ( settings . AspNetCore . HealthChecks . ReadinessEndpointPath ,
63+ TestContext . Current . CancellationToken ) ;
64+ response . EnsureSuccessStatusCode ( ) ;
65+ return response . StatusCode == HttpStatusCode . OK ;
66+ } , TestContext . Current . CancellationToken ) ;
67+
68+
5069 }
5170}
0 commit comments