Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adopt ensureNoDisposablesAreLeakedInTestSuite #193803

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/vs/workbench/services/configuration/browser/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ class FileServiceBasedRemoteUserConfiguration extends Disposable {
protected readonly _onDidChangeConfiguration: Emitter<ConfigurationModel> = this._register(new Emitter<ConfigurationModel>());
readonly onDidChangeConfiguration: Event<ConfigurationModel> = this._onDidChangeConfiguration.event;

private fileWatcherDisposable: IDisposable = Disposable.None;
private directoryWatcherDisposable: IDisposable = Disposable.None;
private readonly fileWatcherDisposable = this._register(new MutableDisposable());
private readonly directoryWatcherDisposable = this._register(new MutableDisposable());

constructor(
private readonly configurationResource: URI,
Expand All @@ -469,22 +469,20 @@ class FileServiceBasedRemoteUserConfiguration extends Disposable {
}

private watchResource(): void {
this.fileWatcherDisposable = this.fileService.watch(this.configurationResource);
this.fileWatcherDisposable.value = this.fileService.watch(this.configurationResource);
}

private stopWatchingResource(): void {
this.fileWatcherDisposable.dispose();
this.fileWatcherDisposable = Disposable.None;
this.fileWatcherDisposable.value = undefined;
}

private watchDirectory(): void {
const directory = this.uriIdentityService.extUri.dirname(this.configurationResource);
this.directoryWatcherDisposable = this.fileService.watch(directory);
this.directoryWatcherDisposable.value = this.fileService.watch(directory);
}

private stopWatchingDirectory(): void {
this.directoryWatcherDisposable.dispose();
this.directoryWatcherDisposable = Disposable.None;
this.directoryWatcherDisposable.value = undefined;
}

async initialize(): Promise<ConfigurationModel> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { IFileService } from 'vs/platform/files/common/files';
import { KeybindingsEditingService, IKeybindingEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
import { FileUserDataProvider } from 'vs/platform/userData/common/fileUserDataProvider';
import { UriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentityService';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { toDisposable } from 'vs/base/common/lifecycle';
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
import { joinPath } from 'vs/base/common/resources';
import { VSBuffer } from 'vs/base/common/buffer';
Expand All @@ -46,6 +46,7 @@ import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
import { UserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfileService';
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';

const ROOT = URI.file('tests').with({ scheme: 'vscode-tests' });

Expand All @@ -65,8 +66,6 @@ suite('ConfigurationEditing', () => {
let workspaceService: WorkspaceService;
let testObject: ConfigurationEditing;

const disposables = new DisposableStore();

suiteSetup(() => {
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
Expand Down Expand Up @@ -97,6 +96,8 @@ suite('ConfigurationEditing', () => {
});
});

const disposables = ensureNoDisposablesAreLeakedInTestSuite();

setup(async () => {
disposables.add(toDisposable(() => sinon.restore()));
const logService = new NullLogService();
Expand All @@ -111,14 +112,14 @@ suite('ConfigurationEditing', () => {
environmentService = TestEnvironmentService;
environmentService.policyFile = joinPath(workspaceFolder, 'policies.json');
instantiationService.stub(IEnvironmentService, environmentService);
const uriIdentityService = new UriIdentityService(fileService);
const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, new UserDataProfilesService(environmentService, fileService, uriIdentityService, logService));
userDataProfileService = new UserDataProfileService(userDataProfilesService.defaultProfile);
const uriIdentityService = disposables.add(new UriIdentityService(fileService));
const userDataProfilesService = instantiationService.stub(IUserDataProfilesService, disposables.add(new UserDataProfilesService(environmentService, fileService, uriIdentityService, logService)));
userDataProfileService = disposables.add(new UserDataProfileService(userDataProfilesService.defaultProfile));
const remoteAgentService = disposables.add(instantiationService.createInstance(RemoteAgentService));
disposables.add(fileService.registerProvider(Schemas.vscodeUserData, disposables.add(new FileUserDataProvider(ROOT.scheme, fileSystemProvider, Schemas.vscodeUserData, userDataProfilesService, uriIdentityService, logService))));
instantiationService.stub(IFileService, fileService);
instantiationService.stub(IRemoteAgentService, remoteAgentService);
workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache() }, environmentService, userDataProfileService, userDataProfilesService, fileService, remoteAgentService, uriIdentityService, new NullLogService(), new FilePolicyService(environmentService.policyFile, fileService, logService)));
workspaceService = disposables.add(new WorkspaceService({ configurationCache: new ConfigurationCache() }, environmentService, userDataProfileService, userDataProfilesService, fileService, remoteAgentService, uriIdentityService, new NullLogService(), disposables.add(new FilePolicyService(environmentService.policyFile, fileService, logService))));
await workspaceService.initialize({
id: hash(workspaceFolder.toString()).toString(16),
uri: workspaceFolder
Expand All @@ -134,8 +135,6 @@ suite('ConfigurationEditing', () => {
testObject = instantiationService.createInstance(ConfigurationEditing, null);
});

teardown(() => disposables.clear());

test('errors cases - invalid key', async () => {
try {
await testObject.writeConfiguration(EditableConfigurationTarget.WORKSPACE, { key: 'unknown.key', value: 'value' }, { donotNotifyError: true });
Expand Down