1919import com .github .copilot .sdk .json .MessageOptions ;
2020
2121/**
22- * Tests for timeout edge cases in {@link CopilotSession#sendAndWait}.
22+ * Regression tests for timeout edge cases in
23+ * {@link CopilotSession#sendAndWait}.
2324 * <p>
24- * These tests prove two defects in the current per-call
25+ * These tests assert two behavioral contracts of the shared
2526 * {@code ScheduledExecutorService} approach:
2627 * <ol>
27- * <li>A timeout fires after {@code close()}, leaking a {@code TimeoutException}
28- * onto the returned future.</li>
29- * <li>Each {@code sendAndWait} call spawns a new OS thread (~1 MB stack),
30- * instead of reusing a shared scheduler thread.</li>
28+ * <li>A pending timeout must NOT fire after {@code close()} and must NOT
29+ * complete the returned future with a {@code TimeoutException} .</li>
30+ * <li>Multiple {@code sendAndWait} calls must reuse a single shared scheduler
31+ * thread rather than spawning a new OS thread per call .</li>
3132 * </ol>
3233 */
3334public class TimeoutEdgeCaseTest {
@@ -62,13 +63,10 @@ public int read() throws IOException {
6263 * After {@code close()}, the future returned by {@code sendAndWait} must NOT be
6364 * completed by a stale timeout.
6465 * <p>
65- * Current buggy behavior: the per-call scheduler is not cancelled by
66- * {@code close()}, so its 2-second timeout fires during the 5-second
67- * {@code session.destroy} RPC wait, completing the future with
68- * {@code TimeoutException}.
69- * <p>
70- * Expected behavior after fix: {@code close()} cancels pending timeouts before
71- * the blocking RPC call, so the future remains incomplete.
66+ * Contract: {@code close()} shuts down the timeout scheduler before the
67+ * blocking {@code session.destroy} RPC call, so any pending timeout task is
68+ * cancelled and the future remains incomplete (not exceptionally completed with
69+ * {@code TimeoutException}).
7270 */
7371 @ Test
7472 void testTimeoutDoesNotFireAfterSessionClose () throws Exception {
@@ -94,13 +92,11 @@ void testTimeoutDoesNotFireAfterSessionClose() throws Exception {
9492 }
9593
9694 /**
97- * A shared scheduler should reuse a single thread across multiple
95+ * A shared scheduler must reuse a single thread across multiple
9896 * {@code sendAndWait} calls, rather than spawning a new OS thread per call.
9997 * <p>
100- * Current buggy behavior: two calls create two {@code sendAndWait-timeout}
101- * threads.
102- * <p>
103- * Expected behavior after fix: two calls still use only one scheduler thread.
98+ * Contract: after two consecutive {@code sendAndWait} calls the number of live
99+ * {@code sendAndWait-timeout} threads must not increase after the second call.
104100 */
105101 @ Test
106102 void testSendAndWaitReusesTimeoutThread () throws Exception {
0 commit comments