Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/test/browser/debugSession.test.ts
3296 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
6
import assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import { ThreadStatusScheduler } from '../../browser/debugSession.js';
9
10
11
suite('DebugSession - ThreadStatusScheduler', () => {
12
const ds = ensureNoDisposablesAreLeakedInTestSuite();
13
14
test('cancel base case', async () => {
15
const scheduler = ds.add(new ThreadStatusScheduler());
16
17
await scheduler.run(Promise.resolve([1]), async (threadId, token) => {
18
assert.strictEqual(threadId, 1);
19
assert.strictEqual(token.isCancellationRequested, false);
20
scheduler.cancel([1]);
21
assert.strictEqual(token.isCancellationRequested, true);
22
});
23
});
24
25
test('cancel global', async () => {
26
const scheduler = ds.add(new ThreadStatusScheduler());
27
28
await scheduler.run(Promise.resolve([1]), async (threadId, token) => {
29
assert.strictEqual(threadId, 1);
30
assert.strictEqual(token.isCancellationRequested, false);
31
scheduler.cancel(undefined);
32
assert.strictEqual(token.isCancellationRequested, true);
33
});
34
});
35
36
test('cancels when new work comes in', async () => {
37
const scheduler = ds.add(new ThreadStatusScheduler());
38
let innerCalled = false;
39
40
await scheduler.run(Promise.resolve([1]), async (threadId, token1) => {
41
assert.strictEqual(threadId, 1);
42
assert.strictEqual(token1.isCancellationRequested, false);
43
await scheduler.run(Promise.resolve([1]), async (_threadId, token2) => {
44
innerCalled = true;
45
assert.strictEqual(token1.isCancellationRequested, true);
46
assert.strictEqual(token2.isCancellationRequested, false);
47
});
48
});
49
50
assert.strictEqual(innerCalled, true);
51
});
52
53
test('cancels slower lookups when new lookup is made', async () => {
54
const scheduler = ds.add(new ThreadStatusScheduler());
55
const innerCalled1: number[] = [];
56
const innerCalled2: number[] = [];
57
58
await Promise.all([
59
scheduler.run(Promise.resolve().then(() => { }).then(() => [1, 3]), async threadId => {
60
innerCalled1.push(threadId);
61
}),
62
scheduler.run(Promise.resolve([1, 2]), async threadId => {
63
innerCalled2.push(threadId);
64
})
65
]);
66
67
assert.deepEqual(innerCalled1, [3]);
68
assert.deepEqual(innerCalled2, [1, 2]);
69
});
70
71
test('allows work with other IDs', async () => {
72
const scheduler = ds.add(new ThreadStatusScheduler());
73
let innerCalled = false;
74
75
await scheduler.run(Promise.resolve([1]), async (threadId, token1) => {
76
assert.strictEqual(threadId, 1);
77
assert.strictEqual(token1.isCancellationRequested, false);
78
await scheduler.run(Promise.resolve([2]), async (_threadId, token2) => {
79
innerCalled = true;
80
assert.strictEqual(token1.isCancellationRequested, false);
81
assert.strictEqual(token2.isCancellationRequested, false);
82
});
83
});
84
85
assert.strictEqual(innerCalled, true);
86
});
87
88
test('cancels when called during reslution', async () => {
89
const scheduler = ds.add(new ThreadStatusScheduler());
90
let innerCalled = false;
91
92
await scheduler.run(Promise.resolve().then(() => scheduler.cancel([1])).then(() => [1]), async () => {
93
innerCalled = true;
94
});
95
96
assert.strictEqual(innerCalled, false);
97
});
98
99
test('global cancels when called during reslution', async () => {
100
const scheduler = ds.add(new ThreadStatusScheduler());
101
let innerCalled = false;
102
103
await scheduler.run(Promise.resolve().then(() => scheduler.cancel(undefined)).then(() => [1]), async () => {
104
innerCalled = true;
105
});
106
107
assert.strictEqual(innerCalled, false);
108
});
109
});
110
111