Skip to content

Commit ee7f834

Browse files
Copilotedburns
andauthored
Fix polling loops to catch TimeoutException and cap per-iteration timeout
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent a50b861 commit ee7f834

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,13 @@ void testShouldGetLastSessionId() throws Exception {
770770
long deadline = System.currentTimeMillis() + 10_000;
771771
while (System.currentTimeMillis() < deadline) {
772772
long remaining = Math.max(1, deadline - System.currentTimeMillis());
773-
lastId = client.getLastSessionId().get(remaining, TimeUnit.MILLISECONDS);
773+
long iterationTimeout = Math.min(remaining, 500);
774+
try {
775+
lastId = client.getLastSessionId().get(iterationTimeout, TimeUnit.MILLISECONDS);
776+
} catch (java.util.concurrent.TimeoutException ignored) {
777+
// RPC call took longer than the per-iteration cap; retry
778+
continue;
779+
}
774780
if (sessionId.equals(lastId)) {
775781
break;
776782
}
@@ -863,7 +869,13 @@ void testShouldGetSessionMetadataById() throws Exception {
863869
long deadline = System.currentTimeMillis() + 10_000;
864870
while (System.currentTimeMillis() < deadline) {
865871
long remaining = Math.max(1, deadline - System.currentTimeMillis());
866-
metadata = client.getSessionMetadata(sessionId).get(remaining, TimeUnit.MILLISECONDS);
872+
long iterationTimeout = Math.min(remaining, 500);
873+
try {
874+
metadata = client.getSessionMetadata(sessionId).get(iterationTimeout, TimeUnit.MILLISECONDS);
875+
} catch (java.util.concurrent.TimeoutException ignored) {
876+
// RPC call took longer than the per-iteration cap; retry
877+
continue;
878+
}
867879
if (metadata != null) {
868880
break;
869881
}

0 commit comments

Comments
 (0)