-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZeroTimeoutContractTest.java
More file actions
47 lines (35 loc) · 1.88 KB
/
ZeroTimeoutContractTest.java
File metadata and controls
47 lines (35 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.Test;
import com.github.copilot.sdk.events.AssistantMessageEvent;
import com.github.copilot.sdk.json.MessageOptions;
/**
* Verifies the documented contract that {@code timeoutMs <= 0} means "no
* timeout" in {@link CopilotSession#sendAndWait(MessageOptions, long)}.
*/
public class ZeroTimeoutContractTest {
@SuppressWarnings("unchecked")
@Test
void sendAndWaitWithZeroTimeoutShouldNotTimeOut() throws Exception {
// Build a session via reflection (package-private constructor)
var ctor = CopilotSession.class.getDeclaredConstructor(String.class, JsonRpcClient.class, String.class);
ctor.setAccessible(true);
var mockRpc = mock(JsonRpcClient.class);
when(mockRpc.invoke(any(), any(), any())).thenReturn(new CompletableFuture<>());
var session = ctor.newInstance("zero-timeout-test", mockRpc, null);
// Per the Javadoc: timeoutMs of 0 means "no timeout".
// The future should NOT complete with TimeoutException.
CompletableFuture<AssistantMessageEvent> result = session.sendAndWait(new MessageOptions().setPrompt("test"),
0);
// Give the scheduler a chance to fire if it was (incorrectly) scheduled
Thread.sleep(200);
// The future should still be pending — not timed out
assertFalse(result.isDone(), "Future should not be done; timeoutMs=0 means no timeout per Javadoc");
}
}