Skip to content

Commit 68fe3bf

Browse files
committed
Use the codeQL.runningTests.numberOfThreads
This setting has existed for a while, but it was not used for some reason.
1 parent 899f988 commit 68fe3bf

File tree

5 files changed

+69
-11
lines changed

5 files changed

+69
-11
lines changed

extensions/ql-vscode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Clear the problems view of all CodeQL query results when a database is removed.
1515
- Add a `View DIL` command on query history items. This opens a text editor containing the Datalog Intermediary Language representation of the compiled query.
1616
- Remove feature flag for the AST Viewer. For more information on how to use the AST Viewer, [see the documentation](https://help.semmle.com/codeql/codeql-for-vscode/procedures/exploring-the-structure-of-your-source-code.html).
17+
- The `codeQL.runningTests.numberOfThreads` setting is now used correctly when running tests.
1718

1819
## 1.3.3 - 16 September 2020
1920

extensions/ql-vscode/src/cli.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { StringDecoder } from 'string_decoder';
99
import * as tk from 'tree-kill';
1010
import * as util from 'util';
1111
import { CancellationToken, Disposable } from 'vscode';
12+
1213
import { BQRSInfo, DecodedBqrsChunk } from './bqrs-cli-types';
14+
import { CliConfig } from './config';
1315
import { DistributionProvider } from './distribution';
1416
import { assertNever } from './helpers-pure';
1517
import { QueryMetadata, SortDirection } from './interface-types';
@@ -122,12 +124,21 @@ export class CodeQLCliServer implements Disposable {
122124
/** A buffer with a single null byte. */
123125
nullBuffer: Buffer;
124126

125-
constructor(private config: DistributionProvider, private logger: Logger) {
127+
constructor(
128+
private distributionProvider: DistributionProvider,
129+
private cliConfig: CliConfig,
130+
private logger: Logger,
131+
) {
126132
this.commandQueue = [];
127133
this.commandInProcess = false;
128134
this.nullBuffer = Buffer.alloc(1);
129-
if (this.config.onDidChangeDistribution) {
130-
this.config.onDidChangeDistribution(() => {
135+
if (this.distributionProvider.onDidChangeDistribution) {
136+
this.distributionProvider.onDidChangeDistribution(() => {
137+
this.restartCliServer();
138+
});
139+
}
140+
if (this.cliConfig.onDidChangeCliConfiguration) {
141+
this.cliConfig.onDidChangeCliConfiguration(() => {
131142
this.restartCliServer();
132143
});
133144
}
@@ -188,7 +199,7 @@ export class CodeQLCliServer implements Disposable {
188199
* Get the path to the CodeQL CLI distribution, or throw an exception if not found.
189200
*/
190201
private async getCodeQlPath(): Promise<string> {
191-
const codeqlPath = await this.config.getCodeQlPathWithoutVersionCheck();
202+
const codeqlPath = await this.distributionProvider.getCodeQlPathWithoutVersionCheck();
192203
if (!codeqlPath) {
193204
throw new Error('Failed to find CodeQL distribution.');
194205
}
@@ -200,7 +211,14 @@ export class CodeQLCliServer implements Disposable {
200211
*/
201212
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
202213
const config = await this.getCodeQlPath();
203-
return spawnServer(config, 'CodeQL CLI Server', ['execute', 'cli-server'], [], this.logger, _data => { /**/ });
214+
return spawnServer(
215+
config,
216+
'CodeQL CLI Server',
217+
['execute', 'cli-server'],
218+
[],
219+
this.logger,
220+
_data => { /**/ }
221+
);
204222
}
205223

206224
private async runCodeQlCliInternal(command: string[], commandArgs: string[], description: string): Promise<string> {
@@ -455,7 +473,8 @@ export class CodeQLCliServer implements Disposable {
455473

456474
const subcommandArgs = [
457475
'--additional-packs', workspaces.join(path.delimiter),
458-
'--threads', '8',
476+
'--threads',
477+
this.cliConfig.numberTestThreads.toString(),
459478
...testPaths
460479
];
461480

extensions/ql-vscode/src/config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const NUMBER_OF_THREADS_SETTING = new Setting('numberOfThreads', RUNNING_QUERIES
6767
const TIMEOUT_SETTING = new Setting('timeout', RUNNING_QUERIES_SETTING);
6868
const MEMORY_SETTING = new Setting('memory', RUNNING_QUERIES_SETTING);
6969
const DEBUG_SETTING = new Setting('debug', RUNNING_QUERIES_SETTING);
70+
const RUNNING_TESTS_SETTING = new Setting('runningTests', ROOT_SETTING);
71+
72+
export const NUMBER_OF_TEST_THREADS_SETTING = new Setting('numberOfThreads', RUNNING_TESTS_SETTING);
7073
export const MAX_QUERIES = new Setting('maxQueries', RUNNING_QUERIES_SETTING);
7174
export const AUTOSAVE_SETTING = new Setting('autoSave', RUNNING_QUERIES_SETTING);
7275

@@ -90,6 +93,14 @@ export interface QueryHistoryConfig {
9093
onDidChangeQueryHistoryConfiguration: Event<void>;
9194
}
9295

96+
const CLI_SETTINGS = [NUMBER_OF_TEST_THREADS_SETTING];
97+
98+
export interface CliConfig {
99+
numberTestThreads: number;
100+
onDidChangeCliConfiguration?: Event<void>;
101+
}
102+
103+
93104
abstract class ConfigListener extends DisposableObject {
94105
protected readonly _onDidChangeConfiguration = this.push(new EventEmitter<void>());
95106

@@ -211,6 +222,21 @@ export class QueryHistoryConfigListener extends ConfigListener implements QueryH
211222
}
212223
}
213224

225+
export class CliConfigListener extends ConfigListener implements CliConfig {
226+
227+
public get numberTestThreads(): number {
228+
return NUMBER_OF_TEST_THREADS_SETTING.getValue();
229+
}
230+
231+
public get onDidChangeCliConfiguration(): Event<void> {
232+
return this._onDidChangeConfiguration.event;
233+
}
234+
235+
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
236+
this.handleDidChangeConfigurationForRelevantSettings(CLI_SETTINGS, e);
237+
}
238+
}
239+
214240
// Enable experimental features
215241

216242
/**

extensions/ql-vscode/src/extension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { AstViewer } from './astViewer';
2020
import * as archiveFilesystemProvider from './archive-filesystem-provider';
2121
import { CodeQLCliServer } from './cli';
2222
import {
23+
CliConfigListener,
2324
DistributionConfigListener,
2425
MAX_QUERIES,
2526
QueryHistoryConfigListener,
@@ -314,7 +315,11 @@ async function activateWithInstalledDistribution(
314315
ctx.subscriptions.push(qlConfigurationListener);
315316

316317
logger.log('Initializing CodeQL cli server...');
317-
const cliServer = new CodeQLCliServer(distributionManager, logger);
318+
const cliServer = new CodeQLCliServer(
319+
distributionManager,
320+
new CliConfigListener(),
321+
logger
322+
);
318323
ctx.subscriptions.push(cliServer);
319324

320325
logger.log('Initializing query server client.');

extensions/ql-vscode/test/pure-tests/query-test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,18 @@ describe('using the query server', function() {
109109
removeAdditionalLogLocation: async () => { /**/ },
110110
getBaseLocation: () => ''
111111
};
112-
cliServer = new cli.CodeQLCliServer({
113-
async getCodeQlPathWithoutVersionCheck(): Promise<string | undefined> {
114-
return codeQlPath;
112+
cliServer = new cli.CodeQLCliServer(
113+
{
114+
async getCodeQlPathWithoutVersionCheck(): Promise<string | undefined> {
115+
return codeQlPath;
116+
},
117+
},
118+
{
119+
numberTestThreads: 2,
120+
onDidChangeCliConfiguration: (() => {}) as any
115121
},
116-
}, logger);
122+
logger
123+
);
117124
qs = new qsClient.QueryServerClient(
118125
{
119126
codeQlPath,

0 commit comments

Comments
 (0)