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

speed up tests #163171

Merged
merged 1 commit into from Oct 10, 2022
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
Expand Up @@ -9,6 +9,7 @@ import { Event } from 'vs/base/common/event';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import { ConfigurationService } from 'vs/platform/configuration/common/configurationService';
Expand All @@ -34,7 +35,7 @@ suite('ConfigurationService', () => {

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

test('simple', async () => {
test('simple', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "bar" }'));
const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
await testObject.initialize();
Expand All @@ -44,9 +45,9 @@ suite('ConfigurationService', () => {

assert.ok(config);
assert.strictEqual(config.foo, 'bar');
});
}));

test('config gets flattened', async () => {
test('config gets flattened', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "testworkbench.editor.tabs": true }'));

const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
Expand All @@ -63,9 +64,9 @@ suite('ConfigurationService', () => {
assert.ok(config.testworkbench);
assert.ok(config.testworkbench.editor);
assert.strictEqual(config.testworkbench.editor.tabs, true);
});
}));

test('error case does not explode', async () => {
test('error case does not explode', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
await fileService.writeFile(settingsResource, VSBuffer.fromString(',,,,'));

const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
Expand All @@ -75,18 +76,18 @@ suite('ConfigurationService', () => {
}>();

assert.ok(config);
});
}));

test('missing file does not explode', async () => {
test('missing file does not explode', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const testObject = disposables.add(new ConfigurationService(URI.file('__testFile'), fileService, new NullPolicyService(), new NullLogService()));
await testObject.initialize();

const config = testObject.getValue<{ foo: string }>();

assert.ok(config);
});
}));

test('trigger configuration change event when file does not exist', async () => {
test('trigger configuration change event when file does not exist', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
await testObject.initialize();
return new Promise<void>((c, e) => {
Expand All @@ -97,9 +98,9 @@ suite('ConfigurationService', () => {
fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "bar" }')).catch(e);
});

});
}));

test('trigger configuration change event when file exists', async () => {
test('trigger configuration change event when file exists', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "bar" }'));
await testObject.initialize();
Expand All @@ -111,9 +112,9 @@ suite('ConfigurationService', () => {
}));
fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "barz" }'));
});
});
}));

test('reloadConfiguration', async () => {
test('reloadConfiguration', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
await fileService.writeFile(settingsResource, VSBuffer.fromString('{ "foo": "bar" }'));

const testObject = disposables.add(new ConfigurationService(settingsResource, fileService, new NullPolicyService(), new NullLogService()));
Expand All @@ -132,9 +133,9 @@ suite('ConfigurationService', () => {
}>();
assert.ok(config);
assert.strictEqual(config.foo, 'changed');
});
}));

test('model defaults', async () => {
test('model defaults', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
interface ITestSetting {
configuration: {
service: {
Expand Down Expand Up @@ -176,9 +177,9 @@ suite('ConfigurationService', () => {
setting = testObject.getValue<ITestSetting>();
assert.ok(setting);
assert.strictEqual(setting.configuration.service.testSetting, 'isChanged');
});
}));

test('lookup', async () => {
test('lookup', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
'id': '_test',
Expand Down Expand Up @@ -212,9 +213,9 @@ suite('ConfigurationService', () => {
assert.strictEqual(res.userValue, 'bar');
assert.strictEqual(res.value, 'bar');

});
}));

test('lookup with null', async () => {
test('lookup with null', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
'id': '_testNull',
Expand Down Expand Up @@ -242,5 +243,5 @@ suite('ConfigurationService', () => {
assert.strictEqual(res.defaultValue, null);
assert.strictEqual(res.value, null);
assert.strictEqual(res.userValue, null);
});
}));
});
41 changes: 21 additions & 20 deletions src/vs/platform/userDataSync/test/common/globalStateSync.test.ts
Expand Up @@ -6,6 +6,7 @@
import * as assert from 'assert';
import { VSBuffer } from 'vs/base/common/buffer';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IFileService } from 'vs/platform/files/common/files';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
Expand Down Expand Up @@ -37,7 +38,7 @@ suite('GlobalStateSync', () => {

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

test('when global state does not exist', async () => {
test('when global state does not exist', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
assert.deepStrictEqual(await testObject.getLastSyncUserData(), null);
let manifest = await testClient.getResourceManifest();
server.reset();
Expand All @@ -62,9 +63,9 @@ suite('GlobalStateSync', () => {
server.reset();
await testObject.sync(manifest);
assert.deepStrictEqual(server.requests, []);
});
}));

test('when global state is created after first sync', async () => {
test('when global state is created after first sync', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
await testObject.sync(await testClient.getResourceManifest());
updateUserStorage('a', 'value1', testClient);

Expand All @@ -82,9 +83,9 @@ suite('GlobalStateSync', () => {
assert.deepStrictEqual(lastSyncUserData!.ref, remoteUserData.ref);
assert.deepStrictEqual(lastSyncUserData!.syncData, remoteUserData.syncData);
assert.deepStrictEqual(JSON.parse(lastSyncUserData!.syncData!.content).storage, { 'a': { version: 1, value: 'value1' } });
});
}));

test('first time sync - outgoing to server (no state)', async () => {
test('first time sync - outgoing to server (no state)', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', testClient);
updateMachineStorage('b', 'value1', testClient);
await updateLocale(testClient);
Expand All @@ -97,9 +98,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'globalState.argv.locale': { version: 1, value: 'en' }, 'a': { version: 1, value: 'value1' } });
});
}));

test('first time sync - incoming from server (no state)', async () => {
test('first time sync - incoming from server (no state)', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', client2);
await updateLocale(client2);
await client2.sync();
Expand All @@ -110,9 +111,9 @@ suite('GlobalStateSync', () => {

assert.strictEqual(readStorage('a', testClient), 'value1');
assert.strictEqual(await readLocale(testClient), 'en');
});
}));

test('first time sync when storage exists', async () => {
test('first time sync when storage exists', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', client2);
await client2.sync();

Expand All @@ -128,9 +129,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value1' }, 'b': { version: 1, value: 'value2' } });
});
}));

test('first time sync when storage exists - has conflicts', async () => {
test('first time sync when storage exists - has conflicts', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', client2);
await client2.sync();

Expand All @@ -146,9 +147,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value1' } });
});
}));

test('sync adding a storage value', async () => {
test('sync adding a storage value', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', testClient);
await testObject.sync(await testClient.getResourceManifest());

Expand All @@ -164,9 +165,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value1' }, 'b': { version: 1, value: 'value2' } });
});
}));

test('sync updating a storage value', async () => {
test('sync updating a storage value', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', testClient);
await testObject.sync(await testClient.getResourceManifest());

Expand All @@ -181,9 +182,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value2' } });
});
}));

test('sync removing a storage value', async () => {
test('sync removing a storage value', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
updateUserStorage('a', 'value1', testClient);
updateUserStorage('b', 'value2', testClient);
await testObject.sync(await testClient.getResourceManifest());
Expand All @@ -200,9 +201,9 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value1' } });
});
}));

test('sync profile state', async () => {
test('sync profile state', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
const client2 = disposableStore.add(new UserDataSyncClient(server));
await client2.setUp(true);
const profile = await client2.instantiationService.get(IUserDataProfilesService).createNamedProfile('profile1');
Expand All @@ -221,7 +222,7 @@ suite('GlobalStateSync', () => {
assert.ok(content !== null);
const actual = parseGlobalState(content!);
assert.deepStrictEqual(actual.storage, { 'a': { version: 1, value: 'value1' } });
});
}));

function parseGlobalState(content: string): IGlobalState {
const syncData: ISyncData = JSON.parse(content);
Expand Down