File tree Expand file tree Collapse file tree
src/test/java/io/github/easy4j/kimi/acp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,6 +89,24 @@ void shouldReturnToNewAfterSpawnFailure() {
8989 assertEquals (KimiAcpState .CLOSED , client .getState ());
9090 }
9191
92+ @ Test
93+ void shouldKeepClosedTerminalWhenCloseRacesInitialize () throws Exception {
94+ KimiAcpClient client = new KimiAcpClient (config ("--slow-initialize" ));
95+ CompletableFuture <String > connecting = CompletableFuture .supplyAsync (client ::connect );
96+
97+ long deadline = System .nanoTime () + TimeUnit .SECONDS .toNanos (2 );
98+ while (client .getState () != KimiAcpState .INITIALIZING && System .nanoTime () < deadline ) {
99+ Thread .sleep (10 );
100+ }
101+ assertEquals (KimiAcpState .INITIALIZING , client .getState ());
102+
103+ client .close ();
104+
105+ assertThrows (ExecutionException .class , () -> connecting .get (2 , TimeUnit .SECONDS ));
106+ assertEquals (KimiAcpState .CLOSED , client .getState (),
107+ "CLOSED must remain terminal even when the connect failure unwinds later" );
108+ }
109+
92110 @ Test
93111 void shouldConnectAndInitialize () {
94112 try (KimiAcpClient client = new KimiAcpClient (config ())) {
You can’t perform that action at this time.
0 commit comments