Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/test/common/chatPerf.test.ts
13406 views
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
import assert from 'assert';
6
import { getMarks } from '../../../../../base/common/performance.js';
7
import { URI } from '../../../../../base/common/uri.js';
8
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
9
import { ChatPerfMark, clearChatMarks, markChat } from '../../common/chatPerf.js';
10
11
suite('chatPerf', () => {
12
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
let sessionResource: URI;
16
17
setup(() => {
18
sessionResource = URI.parse(`test://session/${Date.now()}`);
19
});
20
21
teardown(() => {
22
clearChatMarks(sessionResource);
23
});
24
25
test('markChat emits a mark with the expected prefix', () => {
26
markChat(sessionResource, ChatPerfMark.RequestStart);
27
28
const marks = getMarks().filter(m => m.name.includes(sessionResource.toString()));
29
assert.strictEqual(marks.length, 1);
30
assert.ok(marks[0].name.startsWith('code/chat/'));
31
assert.ok(marks[0].name.endsWith('/request/start'));
32
});
33
34
test('clearChatMarks removes all marks for the session', () => {
35
markChat(sessionResource, ChatPerfMark.RequestStart);
36
markChat(sessionResource, ChatPerfMark.FirstToken);
37
38
clearChatMarks(sessionResource);
39
40
const marks = getMarks().filter(m => m.name.includes(sessionResource.toString()));
41
assert.strictEqual(marks.length, 0);
42
});
43
44
test('clearChatMarks does not affect marks from a different session', () => {
45
const otherSession = URI.parse(`test://session/other-${Date.now()}`);
46
markChat(sessionResource, ChatPerfMark.RequestStart);
47
markChat(otherSession, ChatPerfMark.FirstToken);
48
49
clearChatMarks(sessionResource);
50
51
const remaining = getMarks().filter(m => m.name.includes(otherSession.toString()));
52
assert.strictEqual(remaining.length, 1);
53
54
clearChatMarks(otherSession);
55
});
56
});
57
58