Skip to content

Commit a50b861

Browse files
Copilotedburns
andauthored
fix: use remaining-time-based timeout in polling loops to enforce 10s deadline
The 10s polling deadline in testShouldGetLastSessionId and testShouldGetSessionMetadataById was not actually enforced because each iteration could block up to 30s on the Future.get() call. Now each iteration uses Math.max(1, deadline - currentTimeMillis) as the timeout so the overall wait is bounded by the intended 10s deadline. Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 7f11dcc commit a50b861

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/test/java/com/github/copilot/sdk/CopilotSessionTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,8 @@ void testShouldGetLastSessionId() throws Exception {
769769
String lastId = null;
770770
long deadline = System.currentTimeMillis() + 10_000;
771771
while (System.currentTimeMillis() < deadline) {
772-
lastId = client.getLastSessionId().get(30, TimeUnit.SECONDS);
772+
long remaining = Math.max(1, deadline - System.currentTimeMillis());
773+
lastId = client.getLastSessionId().get(remaining, TimeUnit.MILLISECONDS);
773774
if (sessionId.equals(lastId)) {
774775
break;
775776
}
@@ -861,7 +862,8 @@ void testShouldGetSessionMetadataById() throws Exception {
861862
com.github.copilot.sdk.json.SessionMetadata metadata = null;
862863
long deadline = System.currentTimeMillis() + 10_000;
863864
while (System.currentTimeMillis() < deadline) {
864-
metadata = client.getSessionMetadata(sessionId).get(30, TimeUnit.SECONDS);
865+
long remaining = Math.max(1, deadline - System.currentTimeMillis());
866+
metadata = client.getSessionMetadata(sessionId).get(remaining, TimeUnit.MILLISECONDS);
865867
if (metadata != null) {
866868
break;
867869
}

0 commit comments

Comments
 (0)