Skip to content

Commit 8e5c611

Browse files
Copilotbrunoborges
andcommitted
Fix testResumeSessionWithNewClient by keeping first client alive
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 417560b commit 8e5c611

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,34 +244,34 @@ void testResumeSessionWithSameClient() throws Exception {
244244
void testResumeSessionWithNewClient() throws Exception {
245245
ctx.configureForTest("session", "should_resume_a_session_using_a_new_client");
246246

247-
String sessionId;
248-
249-
// First client - create session
247+
// Use a single try-with-resources for the first client to keep it alive
248+
// throughout the test, matching the behavior of other SDK implementations
250249
try (CopilotClient client1 = ctx.createClient()) {
250+
// Create initial session
251251
CopilotSession session1 = client1.createSession().get();
252-
sessionId = session1.getSessionId();
252+
String sessionId = session1.getSessionId();
253253

254254
AssistantMessageEvent answer = session1.sendAndWait(new MessageOptions().setPrompt("What is 1+1?")).get(60,
255255
TimeUnit.SECONDS);
256256
assertNotNull(answer);
257257
assertTrue(answer.getData().getContent().contains("2"),
258258
"Response should contain 2: " + answer.getData().getContent());
259-
}
260259

261-
// Second client - resume session
262-
try (CopilotClient client2 = ctx.createClient()) {
263-
CopilotSession session2 = client2.resumeSession(sessionId).get();
260+
// Resume using a new client (keeping client1 alive)
261+
try (CopilotClient client2 = ctx.createClient()) {
262+
CopilotSession session2 = client2.resumeSession(sessionId).get();
264263

265-
assertEquals(sessionId, session2.getSessionId());
264+
assertEquals(sessionId, session2.getSessionId());
266265

267-
// When resuming with a new client, validate messages contain expected types
268-
List<AbstractSessionEvent> messages = session2.getMessages().get(60, TimeUnit.SECONDS);
269-
assertTrue(messages.stream().anyMatch(m -> m instanceof UserMessageEvent),
270-
"Should contain user.message event");
271-
assertTrue(messages.stream().anyMatch(m -> "session.resume".equals(m.getType())),
272-
"Should contain session.resume event");
266+
// When resuming with a new client, validate messages contain expected types
267+
List<AbstractSessionEvent> messages = session2.getMessages().get(60, TimeUnit.SECONDS);
268+
assertTrue(messages.stream().anyMatch(m -> m instanceof UserMessageEvent),
269+
"Should contain user.message event");
270+
assertTrue(messages.stream().anyMatch(m -> "session.resume".equals(m.getType())),
271+
"Should contain session.resume event");
273272

274-
session2.close();
273+
session2.close();
274+
}
275275
}
276276
}
277277

0 commit comments

Comments
 (0)