@@ -80,23 +80,16 @@ public static async Task ThrowOnNonZeroExitCode(this IContainer container)
8080 throw await WrapException ( $ "Container exited with exit code { exitCode } ", container ) . ConfigureAwait ( false ) ;
8181 }
8282
83- public static async Task < Exception > WrapException ( TimeoutException exception , IContainer container , string serviceName , int port , TimeSpan timeout )
83+ public static async Task StartAsync ( this IContainer container , string failureMessage )
8484 {
85- string message = $ "{ serviceName } did not respond on port { port } within the given timeout: { timeout } ";
86- return await WrapException ( message , container , exception ) . ConfigureAwait ( false ) ;
87- }
88- public static async Task < Exception > WrapException ( string message , IContainer container , Exception innerException = null )
89- {
90- return new InvalidOperationException ( $ """
91- { message }
92- -
93- { await GetErrors ( container ) . ConfigureAwait ( false ) }
94- -
95- Image: { container . Image . FullName }
96- Name: { ( Exists ( container ) ? container . Name : null ) }
97- Health: { container . Health }
98- State: { container . State }
99- """ , innerException ) ;
85+ try
86+ {
87+ await container . StartAsync ( ) . ConfigureAwait ( false ) ;
88+ }
89+ catch ( TimeoutException timeoutException )
90+ {
91+ throw await WrapException ( failureMessage , container , timeoutException ) . ConfigureAwait ( false ) ;
92+ }
10093 }
10194
10295 public static string GenerateContainerName ( this IImage image )
@@ -123,6 +116,21 @@ await logger.WriteLineAsync($"""
123116 """ ) . ConfigureAwait ( false ) ;
124117 }
125118
119+ private static async Task < Exception > WrapException ( string message , IContainer container , Exception innerException = null )
120+ {
121+ return new InvalidOperationException ( $ """
122+ { message }
123+ -
124+ { await GetErrors ( container ) . ConfigureAwait ( false ) }
125+ -
126+ Name: { ( Exists ( container ) ? container . Name : null ) }
127+ Image: { container . Image . FullName }
128+ State: { container . State }
129+ Health: { container . Health }
130+ HealthCheckFailingStreak: { container . HealthCheckFailingStreak }
131+ """ , innerException ) ;
132+ }
133+
126134 private static async Task < string > GetErrors ( IContainer container )
127135 {
128136 ( _ , string stdErr ) = await container . GetLogsAsync ( ) . ConfigureAwait ( false ) ;
0 commit comments