Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/test/common/debugModel.test.ts
5241 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 { DeferredPromise } from '../../../../../base/common/async.js';
8
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
9
import { mockObject, upcastDeepPartial, upcastPartial } from '../../../../../base/test/common/mock.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
11
import { NullLogService } from '../../../../../platform/log/common/log.js';
12
import { ITextFileService } from '../../../../services/textfile/common/textfiles.js';
13
import { TestStorageService } from '../../../../test/common/workbenchTestServices.js';
14
import { IDebugSession } from '../../common/debug.js';
15
import { DebugModel, ExceptionBreakpoint, FunctionBreakpoint, Thread } from '../../common/debugModel.js';
16
import { MockDebugStorage } from './mockDebug.js';
17
import { runWithFakedTimers } from '../../../../../base/test/common/timeTravelScheduler.js';
18
19
suite('DebugModel', () => {
20
ensureNoDisposablesAreLeakedInTestSuite();
21
22
suite('FunctionBreakpoint', () => {
23
test('Id is saved', () => {
24
const fbp = new FunctionBreakpoint({ name: 'function', enabled: true, hitCondition: 'hit condition', condition: 'condition', logMessage: 'log message' });
25
const strigified = JSON.stringify(fbp);
26
const parsed = JSON.parse(strigified);
27
assert.equal(parsed.id, fbp.getId());
28
});
29
});
30
31
suite('ExceptionBreakpoint', () => {
32
test('Restored matches new', () => {
33
const ebp = new ExceptionBreakpoint({
34
conditionDescription: 'condition description',
35
description: 'description',
36
filter: 'condition',
37
label: 'label',
38
supportsCondition: true,
39
enabled: true,
40
}, 'id');
41
const strigified = JSON.stringify(ebp);
42
const parsed = JSON.parse(strigified);
43
const newEbp = new ExceptionBreakpoint(parsed);
44
assert.ok(ebp.matches(newEbp));
45
});
46
});
47
48
suite('DebugModel', () => {
49
test('refreshTopOfCallstack resolves all returned promises when called multiple times', async () => {
50
return runWithFakedTimers({}, async () => {
51
const topFrameDeferred = new DeferredPromise<void>();
52
const wholeStackDeferred = new DeferredPromise<void>();
53
const fakeThread = mockObject<Thread>()({
54
session: upcastDeepPartial<IDebugSession>({ capabilities: { supportsDelayedStackTraceLoading: true } }),
55
getCallStack: () => [],
56
getStaleCallStack: () => [],
57
});
58
fakeThread.fetchCallStack.callsFake((levels: number) => {
59
return levels === 1 ? topFrameDeferred.p : wholeStackDeferred.p;
60
});
61
fakeThread.getId.returns(1);
62
63
const disposable = new DisposableStore();
64
const storage = disposable.add(new TestStorageService());
65
const model = new DebugModel(disposable.add(new MockDebugStorage(storage)), upcastPartial<ITextFileService>({ isDirty: (e: unknown) => false }), undefined!, new NullLogService());
66
disposable.add(model);
67
68
let top1Resolved = false;
69
let whole1Resolved = false;
70
let top2Resolved = false;
71
let whole2Resolved = false;
72
// eslint-disable-next-line local/code-no-any-casts
73
const result1 = model.refreshTopOfCallstack(fakeThread as any);
74
result1.topCallStack.then(() => top1Resolved = true);
75
result1.wholeCallStack.then(() => whole1Resolved = true);
76
77
// eslint-disable-next-line local/code-no-any-casts
78
const result2 = model.refreshTopOfCallstack(fakeThread as any);
79
result2.topCallStack.then(() => top2Resolved = true);
80
result2.wholeCallStack.then(() => whole2Resolved = true);
81
82
assert.ok(!top1Resolved);
83
assert.ok(!whole1Resolved);
84
assert.ok(!top2Resolved);
85
assert.ok(!whole2Resolved);
86
87
await topFrameDeferred.complete();
88
await result1.topCallStack;
89
await result2.topCallStack;
90
assert.ok(!whole1Resolved);
91
assert.ok(!whole2Resolved);
92
93
await wholeStackDeferred.complete();
94
await result1.wholeCallStack;
95
await result2.wholeCallStack;
96
97
disposable.dispose();
98
});
99
});
100
});
101
});
102
103