Skip to content

Commit 9ccaf9d

Browse files
authored
Merge pull request microsoft#209490 from microsoft/tyriar/test_leak
Clean up some tests, fix some leaks
2 parents 74fff91 + 4ad77cc commit 9ccaf9d

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
7575
userHome: string | undefined;
7676
environmentVariableInfo: IEnvironmentVariableInfo | undefined;
7777
backend: ITerminalBackend | undefined;
78-
readonly capabilities = new TerminalCapabilityStore();
78+
readonly capabilities = this._register(new TerminalCapabilityStore());
7979
readonly shellIntegrationNonce: string;
8080

8181
private _isDisposed: boolean = false;
@@ -154,8 +154,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
154154
this._cwdWorkspaceFolder = terminalEnvironment.getWorkspaceForTerminal(cwd, this._workspaceContextService, this._historyService);
155155
this.ptyProcessReady = this._createPtyProcessReadyPromise();
156156
this._ackDataBufferer = new AckDataBufferer(e => this._process?.acknowledgeDataEvent(e));
157-
this._dataFilter = this._instantiationService.createInstance(SeamlessRelaunchDataFilter);
158-
this._dataFilter.onProcessData(ev => {
157+
this._dataFilter = this._register(this._instantiationService.createInstance(SeamlessRelaunchDataFilter));
158+
this._register(this._dataFilter.onProcessData(ev => {
159159
const data = (typeof ev === 'string' ? ev : ev.data);
160160
const beforeProcessDataEvent: IBeforeProcessDataEvent = { data };
161161
this._onBeforeProcessData.fire(beforeProcessDataEvent);
@@ -166,7 +166,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
166166
}
167167
this._onProcessData.fire(typeof ev !== 'string' ? ev : { data: beforeProcessDataEvent.data, trackCommit: false });
168168
}
169-
});
169+
}));
170170

171171
if (cwd && typeof cwd === 'object') {
172172
this.remoteAuthority = getRemoteAuthority(cwd);
@@ -208,12 +208,14 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
208208
}
209209

210210
private _createPtyProcessReadyPromise(): Promise<void> {
211+
211212
return new Promise<void>(c => {
212-
const listener = this.onProcessReady(() => {
213+
const listener = Event.once(this.onProcessReady)(() => {
213214
this._logService.debug(`Terminal process ready (shellProcessId: ${this.shellProcessId})`);
214-
listener.dispose();
215+
this._store.delete(listener);
215216
c(undefined);
216217
});
218+
this._store.add(listener);
217219
});
218220
}
219221

src/vs/workbench/contrib/terminal/test/browser/terminalInstanceService.test.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,17 @@ import { TestEnvironmentService } from 'vs/workbench/test/browser/workbenchTestS
1818
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
1919

2020
suite('Workbench - TerminalInstanceService', () => {
21-
let instantiationService: TestInstantiationService;
2221
let terminalInstanceService: ITerminalInstanceService;
2322

2423
setup(async () => {
25-
instantiationService = new TestInstantiationService();
26-
// TODO: Should be able to create these services without this config set
27-
instantiationService.stub(IConfigurationService, new TestConfigurationService({
28-
terminal: {
29-
integrated: {
30-
fontWeight: 'normal'
31-
}
32-
}
33-
}));
24+
const instantiationService = new TestInstantiationService();
25+
instantiationService.stub(IConfigurationService, new TestConfigurationService());
3426
instantiationService.stub(IContextKeyService, instantiationService.createInstance(ContextKeyService));
3527
instantiationService.stub(IWorkbenchEnvironmentService, TestEnvironmentService);
3628

3729
terminalInstanceService = instantiationService.createInstance(TerminalInstanceService);
3830
});
3931

40-
teardown(() => {
41-
instantiationService.dispose();
42-
});
43-
4432
ensureNoDisposablesAreLeakedInTestSuite();
4533

4634
suite('convertProfileToShellLaunchConfig', () => {

src/vs/workbench/contrib/terminal/test/browser/terminalProcessManager.test.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { strictEqual } from 'assert';
7+
import { Event } from 'vs/base/common/event';
8+
import { Schemas } from 'vs/base/common/network';
9+
import { URI } from 'vs/base/common/uri';
10+
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
711
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
8-
import { TerminalProcessManager } from 'vs/workbench/contrib/terminal/browser/terminalProcessManager';
912
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
10-
import { ITestInstantiationService, TestTerminalProfileResolverService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
13+
import { NullLogService } from 'vs/platform/log/common/log';
1114
import { IProductService } from 'vs/platform/product/common/productService';
15+
import { ITerminalChildProcess, ITerminalLogService } from 'vs/platform/terminal/common/terminal';
16+
import { ITerminalConfigurationService, ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
17+
import { TerminalConfigurationService } from 'vs/workbench/contrib/terminal/browser/terminalConfigurationService';
18+
import { TerminalProcessManager } from 'vs/workbench/contrib/terminal/browser/terminalProcessManager';
1219
import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable';
1320
import { EnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariableService';
14-
import { Schemas } from 'vs/base/common/network';
15-
import { URI } from 'vs/base/common/uri';
16-
import { ITerminalChildProcess, ITerminalLogService } from 'vs/platform/terminal/common/terminal';
1721
import { ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal';
18-
import { ITerminalConfigurationService, ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
19-
import { DisposableStore } from 'vs/base/common/lifecycle';
20-
import { Event } from 'vs/base/common/event';
22+
import { TestTerminalProfileResolverService, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices';
2123
import { TestProductService } from 'vs/workbench/test/common/workbenchTestServices';
22-
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
23-
import { NullLogService } from 'vs/platform/log/common/log';
24-
import { TerminalConfigurationService } from 'vs/workbench/contrib/terminal/browser/terminalConfigurationService';
2524

2625
class TestTerminalChildProcess implements ITerminalChildProcess {
2726
id: number = 0;
@@ -82,13 +81,12 @@ class TestTerminalInstanceService implements Partial<ITerminalInstanceService> {
8281
}
8382

8483
suite('Workbench - TerminalProcessManager', () => {
85-
let store: DisposableStore;
86-
let instantiationService: ITestInstantiationService;
8784
let manager: TerminalProcessManager;
8885

86+
const store = ensureNoDisposablesAreLeakedInTestSuite();
87+
8988
setup(async () => {
90-
store = new DisposableStore();
91-
instantiationService = workbenchInstantiationService(undefined, store);
89+
const instantiationService = workbenchInstantiationService(undefined, store);
9290
const configurationService = new TestConfigurationService();
9391
await configurationService.setUserConfiguration('editor', { fontFamily: 'foo' });
9492
await configurationService.setUserConfiguration('terminal', {
@@ -101,20 +99,16 @@ suite('Workbench - TerminalProcessManager', () => {
10199
}
102100
});
103101
instantiationService.stub(IConfigurationService, configurationService);
104-
instantiationService.stub(ITerminalConfigurationService, instantiationService.createInstance(TerminalConfigurationService));
102+
instantiationService.stub(ITerminalConfigurationService, store.add(instantiationService.createInstance(TerminalConfigurationService)));
105103
instantiationService.stub(IProductService, TestProductService);
106104
instantiationService.stub(ITerminalLogService, new NullLogService());
107-
instantiationService.stub(IEnvironmentVariableService, instantiationService.createInstance(EnvironmentVariableService));
105+
instantiationService.stub(IEnvironmentVariableService, store.add(instantiationService.createInstance(EnvironmentVariableService)));
108106
instantiationService.stub(ITerminalProfileResolverService, TestTerminalProfileResolverService);
109107
instantiationService.stub(ITerminalInstanceService, new TestTerminalInstanceService());
110108

111109
manager = store.add(instantiationService.createInstance(TerminalProcessManager, 1, undefined, undefined, undefined));
112110
});
113111

114-
teardown(() => store.dispose());
115-
116-
ensureNoDisposablesAreLeakedInTestSuite();
117-
118112
suite('process persistence', () => {
119113
suite('local', () => {
120114
test('regular terminal should persist', async () => {

0 commit comments

Comments
 (0)