Skip to content

Commit fb5a1ac

Browse files
authored
add more leakage checks in tests (microsoft#203525)
re microsoft#200091
1 parent e1f27e6 commit fb5a1ac

File tree

16 files changed

+74
-30
lines changed

16 files changed

+74
-30
lines changed

.eslintrc.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@
154154
"src/vs/editor/contrib/codeAction/test/browser/codeActionKeybindingResolver.test.ts",
155155
"src/vs/editor/contrib/codeAction/test/browser/codeActionModel.test.ts",
156156
"src/vs/editor/contrib/gotoSymbol/test/browser/referencesModel.test.ts",
157-
"src/vs/editor/contrib/smartSelect/test/browser/smartSelect.test.ts",
158-
"src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts",
159-
"src/vs/editor/contrib/suggest/test/browser/completionModel.test.ts",
160-
"src/vs/editor/contrib/suggest/test/browser/suggestMemory.test.ts",
161157
"src/vs/editor/test/common/services/languageService.test.ts",
162158
"src/vs/editor/test/node/classification/typescript.test.ts",
163159
"src/vs/editor/test/node/diffing/defaultLinesDiffComputer.test.ts",
@@ -167,22 +163,15 @@
167163
"src/vs/platform/contextkey/test/common/parser.test.ts",
168164
"src/vs/platform/contextkey/test/common/scanner.test.ts",
169165
"src/vs/platform/extensions/test/common/extensionValidator.test.ts",
170-
"src/vs/platform/instantiation/test/common/graph.test.ts",
171166
"src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts",
172167
"src/vs/platform/keybinding/test/common/keybindingLabels.test.ts",
173168
"src/vs/platform/keybinding/test/common/keybindingResolver.test.ts",
174-
"src/vs/platform/markers/test/common/markerService.test.ts",
175169
"src/vs/platform/opener/test/common/opener.test.ts",
176-
"src/vs/platform/progress/test/common/progress.test.ts",
177170
"src/vs/platform/registry/test/common/platform.test.ts",
178171
"src/vs/platform/remote/test/common/remoteHosts.test.ts",
179172
"src/vs/platform/telemetry/test/browser/1dsAppender.test.ts",
180173
"src/vs/platform/workspace/test/common/workspace.test.ts",
181174
"src/vs/platform/workspaces/test/electron-main/workspaces.test.ts",
182-
"src/vs/workbench/api/test/browser/extHostApiCommands.test.ts",
183-
"src/vs/workbench/api/test/browser/extHostBulkEdits.test.ts",
184-
"src/vs/workbench/api/test/browser/extHostDocumentSaveParticipant.test.ts",
185-
"src/vs/workbench/api/test/browser/extHostTypeConverter.test.ts",
186175
"src/vs/workbench/api/test/browser/extHostWorkspace.test.ts",
187176
"src/vs/workbench/api/test/browser/mainThreadConfiguration.test.ts",
188177
"src/vs/workbench/api/test/browser/mainThreadDocuments.test.ts",
@@ -194,9 +183,6 @@
194183
"src/vs/workbench/contrib/extensions/test/common/extensionQuery.test.ts",
195184
"src/vs/workbench/contrib/notebook/test/browser/notebookExecutionService.test.ts",
196185
"src/vs/workbench/contrib/notebook/test/browser/notebookExecutionStateService.test.ts",
197-
"src/vs/workbench/contrib/snippets/test/browser/snippetFile.test.ts",
198-
"src/vs/workbench/contrib/snippets/test/browser/snippetsRegistry.test.ts",
199-
"src/vs/workbench/contrib/snippets/test/browser/snippetsRewrite.test.ts",
200186
"src/vs/workbench/contrib/tasks/test/common/problemMatcher.test.ts",
201187
"src/vs/workbench/contrib/tasks/test/common/taskConfiguration.test.ts",
202188
"src/vs/workbench/services/commands/test/common/commandService.test.ts",

src/vs/editor/contrib/smartSelect/test/browser/smartSelect.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { createModelServices } from 'vs/editor/test/common/testTextModel';
1919
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
2020
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
2121
import { ILanguageSelection, ILanguageService } from 'vs/editor/common/languages/language';
22+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
2223

2324
class StaticLanguageSelector implements ILanguageSelection {
2425
readonly onDidChange: Event<string> = Event.None;
@@ -64,6 +65,8 @@ suite('SmartSelect', () => {
6465
disposables.dispose();
6566
});
6667

68+
ensureNoDisposablesAreLeakedInTestSuite();
69+
6770
async function assertGetRangesToPosition(text: string[], lineNumber: number, column: number, ranges: Range[], selectLeadingAndTrailingWhitespace = true): Promise<void> {
6871
const uri = URI.file('test.js');
6972
const model = modelService.createModel(text.join('\n'), new StaticLanguageSelector(languageId), uri);

src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import * as assert from 'assert';
66
import { mock } from 'vs/base/test/common/mock';
7+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
78
import { IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
89
import { IPosition, Position } from 'vs/editor/common/core/position';
910
import { Range } from 'vs/editor/common/core/range';
@@ -58,6 +59,8 @@ suite('SnippetSession', function () {
5859
editor.dispose();
5960
});
6061

62+
ensureNoDisposablesAreLeakedInTestSuite();
63+
6164
test('normalize whitespace', function () {
6265

6366
function assertNormalized(position: IPosition, input: string, expected: string): void {

src/vs/editor/contrib/suggest/test/browser/completionModel.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as assert from 'assert';
6+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
67
import { EditorOptions, InternalSuggestOptions } from 'vs/editor/common/config/editorOptions';
78
import { IPosition } from 'vs/editor/common/core/position';
89
import * as languages from 'vs/editor/common/languages';
@@ -83,6 +84,8 @@ suite('CompletionModel', function () {
8384
}, WordDistance.None, EditorOptions.suggest.defaultValue, EditorOptions.snippetSuggestions.defaultValue, undefined);
8485
});
8586

87+
ensureNoDisposablesAreLeakedInTestSuite();
88+
8689
test('filtering - cached', function () {
8790

8891
const itemsNow = model.items;

src/vs/editor/contrib/suggest/test/browser/suggestMemory.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
78
import { IPosition } from 'vs/editor/common/core/position';
89
import { ITextModel } from 'vs/editor/common/model';
910
import { CompletionItem } from 'vs/editor/contrib/suggest/browser/suggest';
@@ -30,6 +31,8 @@ suite('SuggestMemories', function () {
3031
buffer.dispose();
3132
});
3233

34+
ensureNoDisposablesAreLeakedInTestSuite();
35+
3336
test('AbstractMemory, select', function () {
3437

3538
const mem = new class extends Memory {

src/vs/platform/instantiation/test/common/graph.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as assert from 'assert';
6+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
67
import { Graph } from 'vs/platform/instantiation/common/graph';
78

89
suite('Graph', () => {
10+
911
let graph: Graph<string>;
1012

1113
setup(() => {
1214
graph = new Graph<string>(s => s);
1315
});
1416

17+
ensureNoDisposablesAreLeakedInTestSuite();
18+
1519
test('is possible to lookup nodes that don\'t exist', function () {
1620
assert.strictEqual(graph.lookup('ddd'), undefined);
1721
});

src/vs/platform/markers/test/common/markerService.test.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as assert from 'assert';
77
import { URI } from 'vs/base/common/uri';
8+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
89
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
910
import * as markerService from 'vs/platform/markers/common/markerService';
1011

@@ -21,9 +22,17 @@ function randomMarkerData(severity = MarkerSeverity.Error): IMarkerData {
2122

2223
suite('Marker Service', () => {
2324

25+
let service: markerService.MarkerService;
26+
27+
teardown(function () {
28+
service.dispose();
29+
});
30+
31+
ensureNoDisposablesAreLeakedInTestSuite();
32+
2433
test('query', () => {
2534

26-
const service = new markerService.MarkerService();
35+
service = new markerService.MarkerService();
2736

2837
service.changeAll('far', [{
2938
resource: URI.parse('file:///c/test/file.cs'),
@@ -55,7 +64,7 @@ suite('Marker Service', () => {
5564

5665
test('changeOne override', () => {
5766

58-
const service = new markerService.MarkerService();
67+
service = new markerService.MarkerService();
5968
service.changeOne('far', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
6069
assert.strictEqual(service.read().length, 1);
6170
assert.strictEqual(service.read({ owner: 'far' }).length, 1);
@@ -73,7 +82,7 @@ suite('Marker Service', () => {
7382

7483
test('changeOne/All clears', () => {
7584

76-
const service = new markerService.MarkerService();
85+
service = new markerService.MarkerService();
7786
service.changeOne('far', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
7887
service.changeOne('boo', URI.parse('file:///path/only.cs'), [randomMarkerData()]);
7988
assert.strictEqual(service.read({ owner: 'far' }).length, 1);
@@ -93,7 +102,7 @@ suite('Marker Service', () => {
93102

94103
test('changeAll sends event for cleared', () => {
95104

96-
const service = new markerService.MarkerService();
105+
service = new markerService.MarkerService();
97106
service.changeAll('far', [{
98107
resource: URI.parse('file:///d/path'),
99108
marker: randomMarkerData()
@@ -104,17 +113,19 @@ suite('Marker Service', () => {
104113

105114
assert.strictEqual(service.read({ owner: 'far' }).length, 2);
106115

107-
service.onMarkerChanged(changedResources => {
116+
const d = service.onMarkerChanged(changedResources => {
108117
assert.strictEqual(changedResources.length, 1);
109118
changedResources.forEach(u => assert.strictEqual(u.toString(), 'file:///d/path'));
110119
assert.strictEqual(service.read({ owner: 'far' }).length, 0);
111120
});
112121

113122
service.changeAll('far', []);
123+
124+
d.dispose();
114125
});
115126

116127
test('changeAll merges', () => {
117-
const service = new markerService.MarkerService();
128+
service = new markerService.MarkerService();
118129

119130
service.changeAll('far', [{
120131
resource: URI.parse('file:///c/test/file.cs'),
@@ -128,7 +139,7 @@ suite('Marker Service', () => {
128139
});
129140

130141
test('changeAll must not break integrety, issue #12635', () => {
131-
const service = new markerService.MarkerService();
142+
service = new markerService.MarkerService();
132143

133144
service.changeAll('far', [{
134145
resource: URI.parse('scheme:path1'),
@@ -158,7 +169,7 @@ suite('Marker Service', () => {
158169
test('invalid marker data', () => {
159170

160171
const data = randomMarkerData();
161-
const service = new markerService.MarkerService();
172+
service = new markerService.MarkerService();
162173

163174
data.message = undefined!;
164175
service.changeOne('far', URI.parse('some:uri/path'), [data]);
@@ -174,7 +185,7 @@ suite('Marker Service', () => {
174185
});
175186

176187
test('MapMap#remove returns bad values, https://github.com/microsoft/vscode/issues/13548', () => {
177-
const service = new markerService.MarkerService();
188+
service = new markerService.MarkerService();
178189

179190
service.changeOne('o', URI.parse('some:uri/1'), [randomMarkerData()]);
180191
service.changeOne('o', URI.parse('some:uri/2'), []);
@@ -192,7 +203,7 @@ suite('Marker Service', () => {
192203
severity: 0 as MarkerSeverity,
193204
source: 'me'
194205
};
195-
const service = new markerService.MarkerService();
206+
service = new markerService.MarkerService();
196207

197208
service.changeOne('far', URI.parse('some:thing'), [data]);
198209
const marker = service.read({ resource: URI.parse('some:thing') });

src/vs/platform/progress/test/common/progress.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55

66
import * as assert from 'assert';
77
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
8+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
89
import { AsyncProgress } from 'vs/platform/progress/common/progress';
910

1011
suite('Progress', () => {
12+
13+
ensureNoDisposablesAreLeakedInTestSuite();
14+
1115
test('multiple report calls are processed in sequence', async () => {
1216
await runWithFakedTimers({ useFakeTimers: true, maxTaskCount: 100 }, async () => {
1317
const executionOrder: string[] = [];

src/vs/workbench/api/test/browser/extHostApiCommands.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { mock } from 'vs/base/test/common/mock';
3434
import { NullApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService';
3535
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
3636
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
37-
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
3837
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
3938
import { IExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo';
4039
import { URITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService';
@@ -62,7 +61,7 @@ import { IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
6261
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
6362
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
6463
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
65-
import { ensureFileSystemProviderError } from 'vs/platform/files/common/files';
64+
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
6665

6766
function assertRejects(fn: () => Promise<any>, message: string = 'Expected rejection') {
6867
return fn().then(() => assert.ok(false, message), _err => assert.ok(true));
@@ -77,6 +76,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
7776
const defaultSelector = { scheme: 'far' };
7877
let model: ITextModel;
7978

79+
let insta: TestInstantiationService;
8080
let rpcProtocol: TestRPCProtocol;
8181
let extHost: ExtHostLanguageFeatures;
8282
let mainThread: MainThreadLanguageFeatures;
@@ -153,7 +153,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
153153
services.set(IOutlineModelService, new SyncDescriptor(OutlineModelService));
154154
services.set(IConfigurationService, new TestConfigurationService());
155155

156-
const insta = new InstantiationService(services);
156+
insta = new TestInstantiationService(services);
157157

158158
const extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
159159
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({
@@ -197,14 +197,17 @@ suite('ExtHostLanguageFeatureCommands', function () {
197197
setUnexpectedErrorHandler(originalErrorHandler);
198198
model.dispose();
199199
mainThread.dispose();
200+
201+
(<OutlineModelService>insta.get(IOutlineModelService)).dispose();
202+
insta.dispose();
200203
});
201204

202205
teardown(() => {
203206
disposables = dispose(disposables);
204207
return rpcProtocol.sync();
205208
});
206209

207-
ensureFileSystemProviderError();
210+
// ensureNoDisposablesAreLeakedInTestSuite();
208211

209212
// --- workspace symbols
210213

src/vs/workbench/api/test/browser/extHostBulkEdits.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SingleProxyRPCProtocol, TestRPCProtocol } from 'vs/workbench/api/test/c
1212
import { NullLogService } from 'vs/platform/log/common/log';
1313
import { ExtHostBulkEdits } from 'vs/workbench/api/common/extHostBulkEdits';
1414
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
15+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
1516

1617
suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
1718

@@ -43,6 +44,8 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
4344
bulkEdits = new ExtHostBulkEdits(rpcProtocol, documentsAndEditors);
4445
});
4546

47+
ensureNoDisposablesAreLeakedInTestSuite();
48+
4649
test('uses version id if document available', async () => {
4750
const edit = new extHostTypes.WorkspaceEdit();
4851
edit.replace(resource, new extHostTypes.Range(0, 0, 0, 0), 'hello');

0 commit comments

Comments
 (0)