Skip to content

Commit 49bae2d

Browse files
Copilotalexr00
andcommitted
Add unit tests for Copilot refresh exponential backoff logic
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 755e13d commit 49bae2d

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { default as assert } from 'assert';
7+
import { EventType } from '../../common/timelineEvent';
8+
9+
describe('Copilot Refresh Logic', function () {
10+
it('should detect new CopilotStarted events', function () {
11+
// Test the logic for detecting new CopilotStarted events
12+
const initialTimeline = [
13+
{ event: EventType.Commented, id: '1' },
14+
{ event: EventType.CopilotStarted, id: '2' }
15+
];
16+
const initialCopilotStartedEvents = initialTimeline.filter(event => event.event === EventType.CopilotStarted);
17+
assert.strictEqual(initialCopilotStartedEvents.length, 1);
18+
19+
const newTimeline = [
20+
{ event: EventType.Commented, id: '1' },
21+
{ event: EventType.CopilotStarted, id: '2' },
22+
{ event: EventType.CopilotStarted, id: '3' }
23+
];
24+
const newCopilotStartedEvents = newTimeline.filter(event => event.event === EventType.CopilotStarted);
25+
assert.strictEqual(newCopilotStartedEvents.length, 2);
26+
27+
// Should detect new event
28+
assert.strictEqual(newCopilotStartedEvents.length > initialCopilotStartedEvents.length, true);
29+
});
30+
31+
it('should handle empty initial timeline', function () {
32+
const initialTimeline = [];
33+
const initialCopilotStartedEvents = initialTimeline.filter(event => event.event === EventType.CopilotStarted);
34+
assert.strictEqual(initialCopilotStartedEvents.length, 0);
35+
36+
const newTimeline = [
37+
{ event: EventType.CopilotStarted, id: '1' }
38+
];
39+
const newCopilotStartedEvents = newTimeline.filter(event => event.event === EventType.CopilotStarted);
40+
assert.strictEqual(newCopilotStartedEvents.length, 1);
41+
42+
// Should detect new event
43+
assert.strictEqual(newCopilotStartedEvents.length > initialCopilotStartedEvents.length, true);
44+
});
45+
46+
it('should handle no new events', function () {
47+
const initialTimeline = [
48+
{ event: EventType.Commented, id: '1' },
49+
{ event: EventType.CopilotStarted, id: '2' }
50+
];
51+
const initialCopilotStartedEvents = initialTimeline.filter(event => event.event === EventType.CopilotStarted);
52+
assert.strictEqual(initialCopilotStartedEvents.length, 1);
53+
54+
const newTimeline = [
55+
{ event: EventType.Commented, id: '1' },
56+
{ event: EventType.CopilotStarted, id: '2' },
57+
{ event: EventType.Commented, id: '3' }
58+
];
59+
const newCopilotStartedEvents = newTimeline.filter(event => event.event === EventType.CopilotStarted);
60+
assert.strictEqual(newCopilotStartedEvents.length, 1);
61+
62+
// Should not detect new event
63+
assert.strictEqual(newCopilotStartedEvents.length > initialCopilotStartedEvents.length, false);
64+
});
65+
66+
it('should verify exponential backoff delays', function () {
67+
const delays = [500, 1000, 2000, 5000];
68+
69+
// Verify the delays are exponential
70+
assert.strictEqual(delays[0], 500);
71+
assert.strictEqual(delays[1], 1000); // 2x
72+
assert.strictEqual(delays[2], 2000); // 2x
73+
assert.strictEqual(delays[3], 5000); // 2.5x (final value as requested)
74+
75+
// Total time should be 8.5 seconds maximum
76+
const totalTime = delays.reduce((sum, delay) => sum + delay, 0);
77+
assert.strictEqual(totalTime, 8500);
78+
});
79+
});

0 commit comments

Comments
 (0)