Add some config listener tests
This also renames the config listeners for more consistency.
This commit is contained in:
@@ -137,8 +137,8 @@ export class CodeQLCliServer implements Disposable {
|
||||
this.restartCliServer();
|
||||
});
|
||||
}
|
||||
if (this.cliConfig.onDidChangeCliConfiguration) {
|
||||
this.cliConfig.onDidChangeCliConfiguration(() => {
|
||||
if (this.cliConfig.onDidChangeConfiguration) {
|
||||
this.cliConfig.onDidChangeConfiguration(() => {
|
||||
this.restartCliServer();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export interface DistributionConfig {
|
||||
personalAccessToken?: string;
|
||||
ownerName?: string;
|
||||
repositoryName?: string;
|
||||
onDidChangeDistributionConfiguration?: Event<void>;
|
||||
onDidChangeConfiguration?: Event<void>;
|
||||
}
|
||||
|
||||
// Query server configuration
|
||||
@@ -82,7 +82,7 @@ export interface QueryServerConfig {
|
||||
numThreads: number;
|
||||
queryMemoryMb?: number;
|
||||
timeoutSecs: number;
|
||||
onDidChangeQueryServerConfiguration?: Event<void>;
|
||||
onDidChangeConfiguration?: Event<void>;
|
||||
}
|
||||
|
||||
/** When these settings change, the query history should be refreshed. */
|
||||
@@ -90,14 +90,14 @@ const QUERY_HISTORY_SETTINGS = [QUERY_HISTORY_FORMAT_SETTING];
|
||||
|
||||
export interface QueryHistoryConfig {
|
||||
format: string;
|
||||
onDidChangeQueryHistoryConfiguration: Event<void>;
|
||||
onDidChangeConfiguration: Event<void>;
|
||||
}
|
||||
|
||||
const CLI_SETTINGS = [NUMBER_OF_TEST_THREADS_SETTING];
|
||||
|
||||
export interface CliConfig {
|
||||
numberTestThreads: number;
|
||||
onDidChangeCliConfiguration?: Event<void>;
|
||||
onDidChangeConfiguration?: Event<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,10 @@ abstract class ConfigListener extends DisposableObject {
|
||||
private updateConfiguration(): void {
|
||||
this._onDidChangeConfiguration.fire();
|
||||
}
|
||||
|
||||
public get onDidChangeConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration.event;
|
||||
}
|
||||
}
|
||||
|
||||
export class DistributionConfigListener extends ConfigListener implements DistributionConfig {
|
||||
@@ -143,17 +147,13 @@ export class DistributionConfigListener extends ConfigListener implements Distri
|
||||
return PERSONAL_ACCESS_TOKEN_SETTING.getValue() || undefined;
|
||||
}
|
||||
|
||||
public get onDidChangeDistributionConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration.event;
|
||||
}
|
||||
|
||||
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
|
||||
this.handleDidChangeConfigurationForRelevantSettings(DISTRIBUTION_CHANGE_SETTINGS, e);
|
||||
}
|
||||
}
|
||||
|
||||
export class QueryServerConfigListener extends ConfigListener implements QueryServerConfig {
|
||||
private constructor(private _codeQlPath: string) {
|
||||
public constructor(private _codeQlPath = '') {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -199,10 +199,6 @@ export class QueryServerConfigListener extends ConfigListener implements QuerySe
|
||||
return DEBUG_SETTING.getValue<boolean>();
|
||||
}
|
||||
|
||||
public get onDidChangeQueryServerConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration.event;
|
||||
}
|
||||
|
||||
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
|
||||
this.handleDidChangeConfigurationForRelevantSettings(QUERY_SERVER_RESTARTING_SETTINGS, e);
|
||||
}
|
||||
@@ -213,10 +209,6 @@ export class QueryHistoryConfigListener extends ConfigListener implements QueryH
|
||||
this.handleDidChangeConfigurationForRelevantSettings(QUERY_HISTORY_SETTINGS, e);
|
||||
}
|
||||
|
||||
public get onDidChangeQueryHistoryConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration.event;
|
||||
}
|
||||
|
||||
public get format(): string {
|
||||
return QUERY_HISTORY_FORMAT_SETTING.getValue<string>();
|
||||
}
|
||||
@@ -228,10 +220,6 @@ export class CliConfigListener extends ConfigListener implements CliConfig {
|
||||
return NUMBER_OF_TEST_THREADS_SETTING.getValue();
|
||||
}
|
||||
|
||||
public get onDidChangeCliConfiguration(): Event<void> {
|
||||
return this._onDidChangeConfiguration.event;
|
||||
}
|
||||
|
||||
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
|
||||
this.handleDidChangeConfigurationForRelevantSettings(CLI_SETTINGS, e);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class DistributionManager implements DistributionProvider {
|
||||
constructor(extensionContext: ExtensionContext, config: DistributionConfig, versionRange: semver.Range) {
|
||||
this._config = config;
|
||||
this._extensionSpecificDistributionManager = new ExtensionSpecificDistributionManager(extensionContext, config, versionRange);
|
||||
this._onDidChangeDistribution = config.onDidChangeDistributionConfiguration;
|
||||
this._onDidChangeDistribution = config.onDidChangeConfiguration;
|
||||
this._updateCheckRateLimiter = new InvocationRateLimiter(
|
||||
extensionContext,
|
||||
'extensionSpecificDistributionUpdateCheck',
|
||||
|
||||
@@ -278,7 +278,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.subscriptions.push(distributionConfigListener.onDidChangeDistributionConfiguration(() => installOrUpdateThenTryActivate({
|
||||
ctx.subscriptions.push(distributionConfigListener.onDidChangeConfiguration(() => installOrUpdateThenTryActivate({
|
||||
isUserInitiated: true,
|
||||
shouldDisplayMessageWhenNoUpdates: false,
|
||||
allowAutoUpdating: true
|
||||
|
||||
@@ -279,7 +279,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
}
|
||||
)
|
||||
);
|
||||
queryHistoryConfigListener.onDidChangeQueryHistoryConfiguration(() => {
|
||||
queryHistoryConfigListener.onDidChangeConfiguration(() => {
|
||||
this.treeDataProvider.refresh();
|
||||
});
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ export class QueryServerClient extends DisposableObject {
|
||||
constructor(readonly config: QueryServerConfig, readonly cliServer: cli.CodeQLCliServer, readonly opts: ServerOpts, withProgressReporting: WithProgressReporting) {
|
||||
super();
|
||||
// When the query server configuration changes, restart the query server.
|
||||
if (config.onDidChangeQueryServerConfiguration !== undefined) {
|
||||
this.push(config.onDidChangeQueryServerConfiguration(async () => {
|
||||
if (config.onDidChangeConfiguration !== undefined) {
|
||||
this.push(config.onDidChangeConfiguration(async () => {
|
||||
this.logger.log('Restarting query server due to configuration changes...');
|
||||
await this.restartQueryServer();
|
||||
}, this));
|
||||
|
||||
@@ -13,9 +13,11 @@ describe('launching with a minimal workspace', async () => {
|
||||
it('should install the extension', () => {
|
||||
assert(ext);
|
||||
});
|
||||
|
||||
it('should not activate the extension at first', () => {
|
||||
assert(ext!.isActive === false);
|
||||
});
|
||||
|
||||
it('should activate the extension when a .ql file is opened', async function() {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
assert(folders && folders.length === 1);
|
||||
@@ -24,10 +26,9 @@ describe('launching with a minimal workspace', async () => {
|
||||
const document = await vscode.workspace.openTextDocument(documentPath);
|
||||
assert(document.languageId === 'ql');
|
||||
// Delay slightly so that the extension has time to activate.
|
||||
this.timeout(3000);
|
||||
setTimeout(() => {
|
||||
assert(ext!.isActive);
|
||||
}, 1000);
|
||||
this.timeout(4000);
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
assert(ext!.isActive);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'vscode-test';
|
||||
import 'mocha';
|
||||
import * as chaiAsPromised from 'chai-as-promised';
|
||||
import 'sinon-chai';
|
||||
import * as Sinon from 'sinon';
|
||||
import * as chai from 'chai';
|
||||
import { workspace } from 'vscode';
|
||||
|
||||
import {
|
||||
CliConfigListener,
|
||||
QueryHistoryConfigListener,
|
||||
QueryServerConfigListener
|
||||
} from '../../config';
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('config listeners', () => {
|
||||
let sandbox: Sinon.SinonSandbox;
|
||||
beforeEach(() => {
|
||||
sandbox = Sinon.createSandbox();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
interface TestConfig<T> {
|
||||
clazz: new() => {};
|
||||
settings: {
|
||||
name: string;
|
||||
property: string;
|
||||
values: [T, T];
|
||||
}[];
|
||||
}
|
||||
|
||||
const testConfig: TestConfig<string | number | boolean>[] = [
|
||||
{
|
||||
clazz: CliConfigListener,
|
||||
settings: [{
|
||||
name: 'codeQL.runningTests.numberOfThreads',
|
||||
property: 'numberTestThreads',
|
||||
values: [1, 0]
|
||||
}]
|
||||
},
|
||||
{
|
||||
clazz: QueryHistoryConfigListener,
|
||||
settings: [{
|
||||
name: 'codeQL.queryHistory.format',
|
||||
property: 'format',
|
||||
values: ['abc', 'def']
|
||||
}]
|
||||
},
|
||||
{
|
||||
clazz: QueryServerConfigListener,
|
||||
settings: [{
|
||||
name: 'codeQL.runningQueries.numberOfThreads',
|
||||
property: 'numThreads',
|
||||
values: [0, 1]
|
||||
}, {
|
||||
name: 'codeQL.runningQueries.memory',
|
||||
property: 'queryMemoryMb',
|
||||
values: [0, 1]
|
||||
}, {
|
||||
name: 'codeQL.runningQueries.debug',
|
||||
property: 'debug',
|
||||
values: [true, false]
|
||||
}]
|
||||
}
|
||||
];
|
||||
|
||||
testConfig.forEach(config => {
|
||||
describe(config.clazz.name, () => {
|
||||
let listener: any;
|
||||
let spy: Sinon.SinonSpy;
|
||||
beforeEach(() => {
|
||||
listener = new config.clazz();
|
||||
spy = Sinon.spy();
|
||||
listener.onDidChangeConfiguration(spy);
|
||||
});
|
||||
|
||||
config.settings.forEach(setting => {
|
||||
let origValue: any;
|
||||
beforeEach(async () => {
|
||||
origValue = workspace.getConfiguration().get(setting.name);
|
||||
await workspace.getConfiguration().update(setting.name, setting.values[0]);
|
||||
spy.resetHistory();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await workspace.getConfiguration().update(setting.name, origValue);
|
||||
});
|
||||
|
||||
it(`should listen for changes to '${setting.name}'`, async () => {
|
||||
await workspace.getConfiguration().update(setting.name, setting.values[1]);
|
||||
expect(spy.calledOnce).to.be.true;
|
||||
expect(listener[setting.property]).to.eq(setting.values[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -238,7 +238,7 @@ describe('CompletedQuery', () => {
|
||||
|
||||
function mockQueryHistoryConfig(): QueryHistoryConfig {
|
||||
return {
|
||||
onDidChangeQueryHistoryConfiguration: onDidChangeQueryHistoryConfigurationSpy,
|
||||
onDidChangeConfiguration: onDidChangeQueryHistoryConfigurationSpy,
|
||||
format: 'pqr'
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,8 +116,7 @@ describe('using the query server', function() {
|
||||
},
|
||||
},
|
||||
{
|
||||
numberTestThreads: 2,
|
||||
onDidChangeCliConfiguration: (() => {}) as any
|
||||
numberTestThreads: 2
|
||||
},
|
||||
logger
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user