22using System . Collections . Generic ;
33using System . Linq ;
44using System . Reflection ;
5+ using System . Runtime . CompilerServices ;
6+ using Elastic . Managed ;
57using Elastic . Managed . Ephemeral ;
68using FluentAssertions . Common ;
9+ using Tests . Configuration ;
710using Tests . Core . ManagedElasticsearch . Clusters ;
811
912namespace Tests . ClusterLauncher
@@ -23,48 +26,62 @@ public static int Main(string[] arguments)
2326 Environment . SetEnvironmentVariable ( "NEST_INTEGRATION_VERSION" , arguments [ 1 ] , EnvironmentVariableTarget . Process ) ;
2427 Environment . SetEnvironmentVariable ( "NEST_INTEGRATION_SHOW_OUTPUT_AFTER_START" , "1" , EnvironmentVariableTarget . Process ) ;
2528
29+
2630 var cluster = GetClusters ( ) . FirstOrDefault ( c => c . Name . StartsWith ( clusterName , StringComparison . OrdinalIgnoreCase ) ) ;
2731 if ( cluster == null )
2832 {
2933 Console . Error . WriteLine ( $ "No cluster found that starts with '{ clusterName } ") ;
3034 return 4 ;
3135 }
3236
37+ //best effort, wont catch all the things
38+ //https://github.com/dotnet/coreclr/issues/8565
39+ //Don't want to make this windows only by registering a SetConsoleCtrlHandler though P/Invoke.
40+ AppDomain . CurrentDomain . ProcessExit += ( s , ev ) => Instance ? . Dispose ( ) ;
41+ Console . CancelKeyPress += ( s , ev ) => Instance ? . Dispose ( ) ;
42+
3343 if ( ! TryStartClientTestClusterBaseImplementation ( cluster ) && ! TryStartXPackClusterImplementation ( cluster ) )
3444 {
3545 Console . Error . WriteLine ( $ "Could not create an instance of '{ cluster . FullName } ") ;
3646 return 1 ;
3747 }
3848 return 0 ;
3949 }
50+
51+ private static ICluster < EphemeralClusterConfiguration > Instance { get ; set ; }
52+
4053 private static bool TryStartXPackClusterImplementation ( Type cluster )
4154 {
4255 if ( ! ( Activator . CreateInstance ( cluster ) is XPackCluster instance ) ) return false ;
56+ Instance = instance ;
4357 using ( instance )
44- {
45- instance . Start ( ) ;
46- Console . WriteLine ( "Press any key to shutdown the running cluster" ) ;
47- Console . ReadKey ( ) ;
48- instance . Dispose ( ) ;
49- }
50-
51- return true ;
58+ return Run ( instance ) ;
5259 }
5360
61+
5462 private static bool TryStartClientTestClusterBaseImplementation ( Type cluster )
5563 {
5664 if ( ! ( Activator . CreateInstance ( cluster ) is ClientTestClusterBase instance ) ) return false ;
65+ Instance = instance ;
5766 using ( instance )
67+ return Run ( instance ) ;
68+ }
69+
70+ private static bool Run ( ICluster < EphemeralClusterConfiguration > instance )
71+ {
72+ TestConfiguration . Instance . DumpConfiguration ( ) ;
73+ instance . Start ( ) ;
74+ if ( ! instance . Started )
5875 {
59- instance . Start ( ) ;
60- Console . WriteLine ( "Press any key to shutdown the running cluster" ) ;
61- Console . ReadKey ( ) ;
62- instance . Dispose ( ) ;
76+ Console . Error . WriteLine ( $ "Failed to start cluster: '{ instance . GetType ( ) . FullName } ") ;
77+ return false ;
6378 }
79+ Console . WriteLine ( "Press any key to shutdown the running cluster" ) ;
80+ var c = default ( ConsoleKeyInfo ) ;
81+ while ( c . Key != ConsoleKey . Q ) c = Console . ReadKey ( ) ;
6482 return true ;
6583 }
6684
67-
6885 private static Type [ ] GetClusters ( )
6986 {
7087 IEnumerable < Type > types ;
0 commit comments