forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperfTelemetry.test.ts
More file actions
132 lines (115 loc) · 4.71 KB
/
perfTelemetry.test.ts
File metadata and controls
132 lines (115 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// tslint:disable:max-func-body-length no-use-before-declare
import { expect } from 'chai';
import { DebugSession } from 'vscode-debugadapter';
import { StoppedEvent } from 'vscode-debugadapter/lib/debugSession';
import { DebugProtocol } from 'vscode-debugprotocol';
import { TelemetryEvent } from '../../client/debugger/Common/Contracts';
import {
capturePerformanceTelemetry,
PerformanceTelemetryCondition,
sendPerformanceTelemetry
} from '../../client/debugger/Common/telemetry';
import { DebuggerPerformanceTelemetry } from '../../client/telemetry/types';
import { sleep } from '../common';
import { initialize } from '../initialize';
suite('Debugging - Performance Telemetry', () => {
suiteSetup(initialize);
setup(() => MockDebugSession.TelemetryEvents = []);
function testTelemetryEvents(expectedActions: string[]) {
expect(MockDebugSession.TelemetryEvents).lengthOf(expectedActions.length, 'Incorrect number of events');
const actions = MockDebugSession.TelemetryEvents.map(item => (item.body.data as DebuggerPerformanceTelemetry).action);
expect(actions).deep.equal(expectedActions, 'Incorrect actions');
}
test('Event = load', async () => {
const session = new MockDebugSession();
session.launchRequest();
await sleep(501);
session.onPythonProcessLoaded();
testTelemetryEvents(['launch']);
expect((MockDebugSession.TelemetryEvents[0].body.data as DebuggerPerformanceTelemetry).duration).greaterThan(500, 'incorrect duration');
});
test('Event = stopped for stepin', async () => {
const session = new MockDebugSession();
session.launchRequest();
session.onPythonProcessLoaded();
session.stepInRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
testTelemetryEvents(['launch', 'stepIn']);
});
test('Event = stopped for stepout', async () => {
const session = new MockDebugSession();
session.launchRequest();
session.onPythonProcessLoaded();
session.stepOutRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
testTelemetryEvents(['launch', 'stepOut']);
});
test('Event = stopped for continue', async () => {
const session = new MockDebugSession();
session.launchRequest();
session.onPythonProcessLoaded();
session.continueRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
testTelemetryEvents(['launch', 'continue']);
});
test('Event = stopped for next', async () => {
const session = new MockDebugSession();
session.launchRequest();
session.onPythonProcessLoaded();
session.nextRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
testTelemetryEvents(['launch', 'next']);
});
test('Event = stopped for stepout, next, stepin', async () => {
const session = new MockDebugSession();
session.launchRequest();
session.onPythonProcessLoaded();
session.stepOutRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
session.nextRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
session.stepInRequest();
session.sendEvent(new StoppedEvent('some reason', 0));
testTelemetryEvents(['launch', 'stepOut', 'next', 'stepIn']);
});
});
class MockDebugSession extends DebugSession {
public static TelemetryEvents: TelemetryEvent[] = [];
constructor() {
super();
}
@capturePerformanceTelemetry('launch')
// tslint:disable-next-line:no-empty
public launchRequest(): void {
}
// tslint:disable-next-line:no-unnecessary-override
@sendPerformanceTelemetry(PerformanceTelemetryCondition.stoppedEvent)
// tslint:disable-next-line:no-empty
public sendEvent(event: DebugProtocol.Event): void {
if (event instanceof TelemetryEvent) {
MockDebugSession.TelemetryEvents.push(event);
}
}
@sendPerformanceTelemetry(PerformanceTelemetryCondition.always)
// tslint:disable-next-line:no-empty
public onPythonProcessLoaded() {
}
@capturePerformanceTelemetry('stepIn')
// tslint:disable-next-line:no-empty
public stepInRequest(): void {
}
@capturePerformanceTelemetry('stepOut')
// tslint:disable-next-line:no-empty
public stepOutRequest(): void {
}
@capturePerformanceTelemetry('continue')
// tslint:disable-next-line:no-empty
public continueRequest(): void {
}
@capturePerformanceTelemetry('next')
// tslint:disable-next-line:no-empty
public nextRequest(): void {
}
}