@@ -29,19 +29,29 @@ void sendAndWaitWithZeroTimeoutShouldNotTimeOut() throws Exception {
2929 ctor .setAccessible (true );
3030
3131 var mockRpc = mock (JsonRpcClient .class );
32- when (mockRpc .invoke (any (), any (), any ())).thenReturn (new CompletableFuture <>());
33-
34- var session = ctor .newInstance ("zero-timeout-test" , mockRpc , null );
35-
36- // Per the Javadoc: timeoutMs of 0 means "no timeout".
37- // The future should NOT complete with TimeoutException.
38- CompletableFuture <AssistantMessageEvent > result = session .sendAndWait (new MessageOptions ().setPrompt ("test" ),
39- 0 );
40-
41- // Give the scheduler a chance to fire if it was (incorrectly) scheduled
42- Thread .sleep (200 );
43-
44- // The future should still be pending — not timed out
45- assertFalse (result .isDone (), "Future should not be done; timeoutMs=0 means no timeout per Javadoc" );
32+ when (mockRpc .invoke (any (), any (), any ())).thenAnswer (invocation -> {
33+ Object method = invocation .getArgument (0 );
34+ if ("session.destroy" .equals (method )) {
35+ // Make session.close() non-blocking by completing destroy immediately
36+ return CompletableFuture .completedFuture (null );
37+ }
38+ // For other calls (e.g., message send), return an incomplete future so the
39+ // sendAndWait result does not complete due to a mock response.
40+ return new CompletableFuture <>();
41+ });
42+
43+ try (var session = ctor .newInstance ("zero-timeout-test" , mockRpc , null )) {
44+
45+ // Per the Javadoc: timeoutMs of 0 means "no timeout".
46+ // The future should NOT complete with TimeoutException.
47+ CompletableFuture <AssistantMessageEvent > result = session
48+ .sendAndWait (new MessageOptions ().setPrompt ("test" ), 0 );
49+
50+ // Give the scheduler a chance to fire if it was (incorrectly) scheduled
51+ Thread .sleep (200 );
52+
53+ // The future should still be pending — not timed out
54+ assertFalse (result .isDone (), "Future should not be done; timeoutMs=0 means no timeout per Javadoc" );
55+ }
4656 }
4757}
0 commit comments