Skip to content

Commit b711289

Browse files
Add test for default timeout reset behavior and complete implementation
Co-authored-by: andrea-tomassi <[email protected]>
1 parent 0f102f5 commit b711289

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/shared/protocol.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,58 @@ describe("protocol tests", () => {
481481
await Promise.resolve();
482482
await expect(requestPromise).resolves.toEqual({ result: "success" });
483483
});
484+
485+
test("should reset timeout by default when progress notification is received", async () => {
486+
await protocol.connect(transport);
487+
const request = { method: "example", params: {} };
488+
const mockSchema: ZodType<{ result: string }> = z.object({
489+
result: z.string(),
490+
});
491+
const onProgressMock = jest.fn();
492+
// Don't specify resetTimeoutOnProgress, should default to true
493+
const requestPromise = protocol.request(request, mockSchema, {
494+
timeout: 1000,
495+
onprogress: onProgressMock,
496+
});
497+
498+
// Advance past most of the timeout period
499+
jest.advanceTimersByTime(900);
500+
501+
// Send progress notification - should reset timeout
502+
if (transport.onmessage) {
503+
transport.onmessage({
504+
jsonrpc: "2.0",
505+
method: "notifications/progress",
506+
params: {
507+
progressToken: 0,
508+
progress: 50,
509+
total: 100,
510+
},
511+
});
512+
}
513+
await Promise.resolve();
514+
515+
expect(onProgressMock).toHaveBeenCalledWith({
516+
progress: 50,
517+
total: 100,
518+
});
519+
520+
// Advance another 900ms (would have timed out without reset)
521+
jest.advanceTimersByTime(900);
522+
523+
// Send final response
524+
if (transport.onmessage) {
525+
transport.onmessage({
526+
jsonrpc: "2.0",
527+
id: 0,
528+
result: { result: "completed" },
529+
});
530+
}
531+
await Promise.resolve();
532+
533+
// Should complete successfully because timeout was reset
534+
await expect(requestPromise).resolves.toEqual({ result: "completed" });
535+
});
484536
});
485537

486538
describe("Debounced Notifications", () => {

0 commit comments

Comments
 (0)