11namespace Shared . IntegrationTesting ;
22
3- using System ;
4- using System . Collections . Generic ;
5- using System . Data ;
6- using System . Diagnostics ;
7- using System . IO ;
8- using System . Linq ;
9- using System . Net ;
10- using System . Net . Http ;
11- using System . Net . Security ;
12- using System . Threading ;
13- using System . Threading . Tasks ;
143using Ductus . FluentDocker . Builders ;
154using Ductus . FluentDocker . Commands ;
165using Ductus . FluentDocker . Common ;
2514using Logger ;
2615using Microsoft . Data . SqlClient ;
2716using Microsoft . EntityFrameworkCore . Diagnostics ;
17+ using Microsoft . Extensions . Diagnostics . HealthChecks ;
2818using Newtonsoft . Json ;
2919using Shouldly ;
20+ using System ;
21+ using System . Collections . Generic ;
22+ using System . Data ;
23+ using System . Diagnostics ;
24+ using System . IO ;
25+ using System . Linq ;
26+ using System . Net ;
27+ using System . Net . Http ;
28+ using System . Net . Security ;
29+ using System . Threading ;
30+ using System . Threading . Tasks ;
3031
3132public enum DockerEnginePlatform {
3233 Unknown ,
@@ -783,8 +784,8 @@ await Retry.For(async () =>
783784 } ) ;
784785 }
785786
786- protected async Task DoHealthCheck ( ContainerType containerType ) {
787- ( String , Int32 ) containerDetails = containerType switch {
787+ protected async Task DoHealthCheck ( ContainerType containerType ) {
788+ ( String , Int32 ) containerDetails = containerType switch {
788789 ContainerType . CallbackHandler => ( "http" , this . CallbackHandlerPort ) ,
789790 ContainerType . FileProcessor => ( "http" , this . FileProcessorPort ) ,
790791 ContainerType . MessagingService => ( "http" , this . MessagingServicePort ) ,
@@ -799,20 +800,23 @@ protected async Task DoHealthCheck(ContainerType containerType){
799800 return ;
800801
801802 await Retry . For ( async ( ) => {
802- this . Trace ( $ "About to do health check for { containerType } ") ;
803+ this . Trace ( $ "About to do health check for { containerType } ") ;
803804
804- String healthCheck =
805- await this . HealthCheckClient . PerformHealthCheck ( containerDetails . Item1 , "127.0.0.1" , containerDetails . Item2 , CancellationToken . None ) ;
805+ SimpleResults . Result < String > healthCheckResult = await this . HealthCheckClient . PerformHealthCheck ( containerDetails . Item1 , "127.0.0.1" , containerDetails . Item2 , CancellationToken . None ) ;
806806
807- HealthCheckResult result = JsonConvert . DeserializeObject < HealthCheckResult > ( healthCheck ) ;
807+ if ( healthCheckResult . IsSuccess ) {
808+ HealthChecks . HealthCheckResult result = JsonConvert . DeserializeObject < HealthChecks . HealthCheckResult > ( healthCheckResult . Data ) ;
808809
809- this . Trace ( $ "health check complete for { containerType } result is [{ healthCheck } ]") ;
810+ this . Trace ( $ "health check complete for { containerType } result is [{ healthCheckResult . Data } ]") ;
810811
811- result . Status . ShouldBe ( HealthCheckStatus . Healthy . ToString ( ) , $ "Service Type: { containerType } Details { healthCheck } ") ;
812- this . Trace ( $ "health check complete for { containerType } ") ;
813- } ,
814- TimeSpan . FromMinutes ( 3 ) ,
815- TimeSpan . FromSeconds ( 20 ) ) ;
812+ result . Status . ShouldBe ( HealthCheckStatus . Healthy . ToString ( ) , $ "Service Type: { containerType } Details { healthCheckResult . Data } ") ;
813+ this . Trace ( $ "health check complete for { containerType } ") ;
814+ }
815+ else {
816+ this . Trace ( $ "health check failed for { containerType } ") ;
817+ throw new Exception ( $ "Health check failed for { containerType } [{ healthCheckResult . Message } ]") ;
818+ }
819+ } , TimeSpan . FromMinutes ( 3 ) , TimeSpan . FromSeconds ( 20 ) ) ;
816820 }
817821
818822 protected void Error ( String message , Exception ex ) {
0 commit comments