Skip to content

Commit f0db763

Browse files
authored
Dispose instances of test instantiation service (microsoft#187482)
* Dispose instances of test instantiation service This will call `sinon.restore()` and prevent a memory leak Part of microsoft#187471 * Fix interfering terminal tests * Remove `async` from terminal test suite * Fix `any`
1 parent 79c0220 commit f0db763

File tree

57 files changed

+231
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+231
-43
lines changed

src/vs/editor/test/browser/testCodeEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export function createCodeEditorServices(disposables: DisposableStore, services:
201201
define(ILanguageFeatureDebounceService, LanguageFeatureDebounceService);
202202
define(ILanguageFeaturesService, LanguageFeaturesService);
203203

204-
const instantiationService = new TestInstantiationService(services, true);
204+
const instantiationService = disposables.add(new TestInstantiationService(services, true));
205205
disposables.add(toDisposable(() => {
206206
for (const id of serviceIdentifiers) {
207207
const instanceOrDescriptor = services.get(id);

src/vs/editor/test/common/services/textResourceConfigurationService.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { URI } from 'vs/base/common/uri';
1515

1616
suite('TextResourceConfigurationService - Update', () => {
1717

18+
let instantiationService: TestInstantiationService;
1819
let configurationValue: IConfigurationValue<any> = {};
1920
let updateArgs: any[];
2021
const configurationService = new class extends TestConfigurationService {
@@ -30,13 +31,17 @@ suite('TextResourceConfigurationService - Update', () => {
3031
let testObject: TextResourceConfigurationService;
3132

3233
setup(() => {
33-
const instantiationService = new TestInstantiationService();
34+
instantiationService = new TestInstantiationService();
3435
instantiationService.stub(IModelService, <Partial<IModelService>>{ getModel() { return null; } });
3536
instantiationService.stub(ILanguageService, <Partial<ILanguageService>>{ guessLanguageIdByFilepathOrFirstLine() { return language; } });
3637
instantiationService.stub(IConfigurationService, configurationService);
3738
testObject = instantiationService.createInstance(TextResourceConfigurationService);
3839
});
3940

41+
teardown(() => {
42+
instantiationService.dispose();
43+
});
44+
4045
test('updateValue writes without target and overrides when no language is defined', async () => {
4146
const resource = URI.file('someFile');
4247
await testObject.updateValue(resource, 'a', 'b');

src/vs/platform/contextkey/test/browser/contextkey.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,23 @@ suite('ContextKeyService', () => {
8383
const disposables = new DisposableStore();
8484
const configurationService: IConfigurationService = new TestConfigurationService();
8585
const contextKeyService: IContextKeyService = disposables.add(new ContextKeyService(configurationService));
86-
const instantiationService = new TestInstantiationService(new ServiceCollection(
86+
const instantiationService = disposables.add(new TestInstantiationService(new ServiceCollection(
8787
[IConfigurationService, configurationService],
8888
[IContextKeyService, contextKeyService],
8989
[ITelemetryService, new class extends mock<ITelemetryService>() {
9090
override async publicLog2() {
9191
//
9292
}
9393
}]
94-
));
94+
)));
9595

9696
const uri = URI.parse('test://abc');
9797
contextKeyService.createKey<string>('notebookCellResource', undefined).set(uri.toString());
9898
instantiationService.invokeFunction(setContext, 'jupyter.runByLineCells', JSON.parse(JSON.stringify([uri])));
9999

100100
const expr = ContextKeyExpr.in('notebookCellResource', 'jupyter.runByLineCells');
101101
assert.deepStrictEqual(contextKeyService.contextMatchesRules(expr), true);
102+
disposables.dispose();
102103
});
103104

104105
test('suppress update event from parent when one key is overridden by child', () => {

src/vs/platform/extensionManagement/test/common/extensionsProfileScannerService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ suite('ExtensionsProfileScannerService', () => {
3333
let instantiationService: TestInstantiationService;
3434

3535
setup(async () => {
36-
instantiationService = new TestInstantiationService();
36+
instantiationService = disposables.add(new TestInstantiationService());
3737
const logService = new NullLogService();
3838
const fileService = disposables.add(new FileService(logService));
3939
const fileSystemProvider = disposables.add(new InMemoryFileSystemProvider());

src/vs/platform/extensionManagement/test/node/extensionsScannerService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ suite('NativeExtensionsScanerService Test', () => {
6060

6161
setup(async () => {
6262
translations = {};
63-
instantiationService = new TestInstantiationService();
63+
instantiationService = disposables.add(new TestInstantiationService());
6464
const logService = new NullLogService();
6565
const fileService = disposables.add(new FileService(logService));
6666
const fileSystemProvider = disposables.add(new InMemoryFileSystemProvider());

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

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

66
import * as sinon from 'sinon';
7-
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
7+
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
88
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
99
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
1010
import { InstantiationService, Trace } from 'vs/platform/instantiation/common/instantiationService';
@@ -17,7 +17,7 @@ interface IServiceMock<T> {
1717

1818
const isSinonSpyLike = (fn: Function): fn is sinon.SinonSpy => fn && 'callCount' in fn;
1919

20-
export class TestInstantiationService extends InstantiationService {
20+
export class TestInstantiationService extends InstantiationService implements IDisposable {
2121

2222
private _servciesMap: Map<ServiceIdentifier<any>, any>;
2323

@@ -129,6 +129,10 @@ export class TestInstantiationService extends InstantiationService {
129129
override createChild(services: ServiceCollection): TestInstantiationService {
130130
return new TestInstantiationService(services, false, this);
131131
}
132+
133+
dispose() {
134+
sinon.restore();
135+
}
132136
}
133137

134138
interface SinonOptions {
@@ -157,7 +161,7 @@ export function createServices(disposables: DisposableStore, services: ServiceId
157161
define(id, ctor);
158162
}
159163

160-
const instantiationService = new TestInstantiationService(serviceCollection, true);
164+
const instantiationService = disposables.add(new TestInstantiationService(serviceCollection, true));
161165
disposables.add(toDisposable(() => {
162166
for (const id of serviceIdentifiers) {
163167
const instanceOrDescriptor = serviceCollection.get(id);

src/vs/platform/telemetry/test/common/telemetryLogAppender.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ suite('TelemetryLogAdapter', () => {
9393
const testObject = new TelemetryLogAppender(new NullLogService(), testLoggerService, testInstantiationService.stub(IEnvironmentService, {}), testInstantiationService.stub(IProductService, {}));
9494
testObject.log('testEvent', { hello: 'world', isTrue: true, numberBetween1And3: 2 });
9595
assert.strictEqual(testLoggerService.createLogger().logs.length, 2);
96+
testInstantiationService.dispose();
9697
});
9798

9899
test('Log Telemetry if log level is trace', async () => {
@@ -108,5 +109,6 @@ suite('TelemetryLogAdapter', () => {
108109
isTrue: 1, numberBetween1And3: 2
109110
}
110111
}]));
112+
testInstantiationService.dispose();
111113
});
112114
});

src/vs/platform/terminal/test/common/requestStore.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ suite('RequestStore', () => {
1717
instantiationService.stub(ILogService, new LogService(new ConsoleLogger()));
1818
});
1919

20+
teardown(() => {
21+
instantiationService.dispose();
22+
});
23+
2024
test('should resolve requests', async () => {
2125
const store: RequestStore<{ data: string }, { arg: string }> = instantiationService.createInstance(RequestStore<{ data: string }, { arg: string }>, undefined);
2226
let eventArgs: { requestId: number; arg: string } | undefined;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ suite('ExtHostAuthentication', () => {
127127
{ supportsMultipleAccounts: true }));
128128
});
129129

130+
suiteTeardown(() => {
131+
instantiationService.dispose();
132+
});
133+
130134
teardown(() => {
131135
disposables.dispose();
132136
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ suite('ExtHostLanguageFeatures', function () {
6767
let rpcProtocol: TestRPCProtocol;
6868
let languageFeaturesService: ILanguageFeaturesService;
6969
let originalErrorHandler: (e: any) => any;
70+
let instantiationService: TestInstantiationService;
7071

7172
suiteSetup(() => {
7273

@@ -87,7 +88,7 @@ suite('ExtHostLanguageFeatures', function () {
8788
// Use IInstantiationService to get typechecking when instantiating
8889
let inst: IInstantiationService;
8990
{
90-
const instantiationService = new TestInstantiationService();
91+
instantiationService = new TestInstantiationService();
9192
instantiationService.stub(IMarkerService, MarkerService);
9293
instantiationService.set(ILanguageFeaturesService, languageFeaturesService);
9394
instantiationService.set(IUriIdentityService, new class extends mock<IUriIdentityService>() {
@@ -140,6 +141,7 @@ suite('ExtHostLanguageFeatures', function () {
140141
setUnexpectedErrorHandler(originalErrorHandler);
141142
model.dispose();
142143
mainThread.dispose();
144+
instantiationService.dispose();
143145
});
144146

145147
teardown(() => {

0 commit comments

Comments
 (0)