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 2121import static org .junit .jupiter .api .Assertions .assertThrows ;
2222import static org .junit .jupiter .api .Assertions .assertTrue ;
2323
24+ import java .lang .reflect .Field ;
2425import java .nio .file .Paths ;
2526import java .util .ArrayList ;
2627import java .util .List ;
@@ -183,6 +184,29 @@ void shouldAllowRetryAfterFailedConnectWithoutLeakingProcess() {
183184 assertFalse (client .isClosed (), "failed connect must leave the client open for a retry" );
184185 }
185186
187+ @ Test
188+ void shouldForceTerminateOwnedProcessOnClose () throws Exception {
189+ KimiAcpClient client = new KimiAcpClient (config ("--ignore-term" ));
190+ client .connect ();
191+
192+ Field processField = KimiAcpClient .class .getDeclaredField ("process" );
193+ processField .setAccessible (true );
194+ Process child = (Process ) processField .get (client );
195+ assertTrue (child .isAlive ());
196+
197+ client .close ();
198+
199+ boolean aliveAfterClose = child .isAlive ();
200+ if (aliveAfterClose ) {
201+ child .destroyForcibly ();
202+ child .waitFor (2 , TimeUnit .SECONDS );
203+ }
204+
205+ assertFalse (aliveAfterClose ,
206+ "close must not return while its owned ACP process is still alive" );
207+ assertEquals (KimiAcpState .CLOSED , client .getState ());
208+ }
209+
186210 @ Test
187211 void shouldRejectUseAfterClose () {
188212 KimiAcpClient client = new KimiAcpClient (config ());
You can’t perform that action at this time.
0 commit comments