Skip to content

Commit c85ef15

Browse files
committed
Test cleanups
- Avoid Installing `xvfb` since it is already available. - Ensure `supportsNewQueryServer()` takes the CLI version into account - Always run the new query server tests on v2.11.1 and later - Avoid printing directory contents in `run-remote-query-tests` - Run tests with `--disable-workspace-trust` to avoid a non-fatal error being thrown from the dialog service. - Ensure the exit code of the extension host while running integration tests is the exit code of the actual process. Otherwise, there is a possibility that an error exit code is swallowed up and ignored. - Remove a duplicate unhandledRejection handler. - Handle Exit code 7 from windows. This appears to be a failure on exiting and unrelated to the tests. - Fix handling of configuration in tests: 1. It is not possible to update a configuration setting for internal settings like `codeql.canary`. 2. On windows CI, updating configuration after global teardown. So, on tests avoid resetting test configuration when tests are over. Also, I tried to remove all those pesky errors in the logs like: > [2094:1017/235357.424002:ERROR:bus.cc(398)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") I was following advice from here, but I can't get it working. - microsoft/vscode-test#127 - electron/electron#31981
1 parent 4fd9b54 commit c85ef15

File tree

12 files changed

+63
-73
lines changed

12 files changed

+63
-73
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
env:
122122
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
123123
run: |
124-
sudo apt-get install xvfb
124+
unset DBUS_SESSION_BUS_ADDRESS
125125
/usr/bin/xvfb-run npm run integration
126126
127127
- name: Run integration tests (Windows)
@@ -188,6 +188,7 @@ jobs:
188188
working-directory: extensions/ql-vscode
189189
if: matrix.os == 'ubuntu-latest'
190190
run: |
191+
unset DBUS_SESSION_BUS_ADDRESS
191192
/usr/bin/xvfb-run npm run cli-integration
192193
193194
- name: Run CLI tests (Windows)

extensions/ql-vscode/src/cli.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ export class CliVersionConstraint {
13331333
/**
13341334
* CLI version that supports the new query server.
13351335
*/
1336-
public static CLI_VERSION_WITH_NEW_QUERY_SERVER = new SemVer('2.11.0');
1336+
public static CLI_VERSION_WITH_NEW_QUERY_SERVER = new SemVer('2.11.1');
13371337

13381338
constructor(private readonly cli: CodeQLCliServer) {
13391339
/**/
@@ -1414,8 +1414,11 @@ export class CliVersionConstraint {
14141414
async supportsNewQueryServer() {
14151415
// TODO while under development, users _must_ opt-in to the new query server
14161416
// by setting the `codeql.canaryQueryServer` setting to `true`.
1417-
// Ignore the version check for now.
1418-
return allowCanaryQueryServer();
1419-
// return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
1417+
return allowCanaryQueryServer() &&
1418+
this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
1419+
}
1420+
1421+
async supportsNewQueryServerForTests() {
1422+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
14201423
}
14211424
}

extensions/ql-vscode/src/config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ export class Setting {
1111
name: string;
1212
parent?: Setting;
1313

14-
constructor(name: string, parent?: Setting) {
14+
constructor(name: string, parent?: Setting, public readonly isHidden = false) {
1515
this.name = name;
1616
this.parent = parent;
17+
1718
ALL_SETTINGS.push(this);
1819
}
1920

@@ -327,7 +328,7 @@ export function isQuickEvalCodelensEnabled() {
327328
/**
328329
* Enables canary features of this extension. Recommended for all internal users.
329330
*/
330-
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING);
331+
export const CANARY_FEATURES = new Setting('canary', ROOT_SETTING, true);
331332

332333
export function isCanary() {
333334
return !!CANARY_FEATURES.getValue<boolean>();
@@ -336,7 +337,7 @@ export function isCanary() {
336337
/**
337338
* Enables the experimental query server
338339
*/
339-
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING);
340+
export const CANARY_QUERY_SERVER = new Setting('canaryQueryServer', ROOT_SETTING, true);
340341

341342

342343
export function allowCanaryQueryServer() {

extensions/ql-vscode/src/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ fs.ensureDirSync(upgradesTmpDir);
2222

2323
export const tmpDirDisposal = {
2424
dispose: () => {
25-
tmpDir.removeCallback();
25+
try {
26+
tmpDir.removeCallback();
27+
} catch (e) {
28+
void logger.log(`Failed to remove temporary directory ${tmpDir.name}: ${e}`);
29+
}
2630
}
2731
};
2832

extensions/ql-vscode/src/vscode-tests/cli-integration/global.helper.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ import { CUSTOM_CODEQL_PATH_SETTING } from '../../config';
1414

1515
export const DB_URL = 'https://github.com/github/vscode-codeql/files/5586722/simple-db.zip';
1616

17-
process.addListener('unhandledRejection', (reason) => {
18-
if (reason instanceof Error && reason.message === 'Canceled') {
19-
console.log('Cancellation requested after the test has ended.');
20-
process.exit(0);
21-
} else {
22-
fail(String(reason));
23-
}
24-
});
25-
2617
// We need to resolve the path, but the final three segments won't exist until later, so we only resolve the
2718
// first portion of the path.
2819
export const dbLoc = path.join(fs.realpathSync(path.join(__dirname, '../../../')), 'build/tests/db.zip');
@@ -84,15 +75,25 @@ export default function(mocha: Mocha) {
8475
// This shuts down the extension and can only be run after all tests have completed.
8576
// If this is not called, then the test process will hang.
8677
if ('dispose' in extension) {
87-
extension.dispose();
78+
try {
79+
extension.dispose();
80+
} catch (e) {
81+
console.warn('Failed to dispose extension', e);
82+
}
8883
}
8984
}
9085
);
9186

9287
// ensure temp directory is cleaned up.
9388
(mocha.options as any).globalTeardown.push(
9489
() => {
95-
removeStorage?.();
90+
try {
91+
removeStorage?.();
92+
} catch (e) {
93+
// we are exiting anyway so don't worry about it.
94+
// most likely the directory this is a test on Windows and some files are locked.
95+
console.warn(`Failed to remove storage directory '${storagePath}': ${e}`);
96+
}
9697
}
9798
);
9899

extensions/ql-vscode/src/vscode-tests/cli-integration/new-query.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { QueryResultType } from '../../pure/new-messages';
1616
import { cleanDatabases, dbLoc, storagePath } from './global.helper';
1717
import { importArchiveDatabase } from '../../databaseFetcher';
1818

19-
2019
const baseDir = path.join(__dirname, '../../../test/data');
2120

2221
const tmpDir = tmp.dirSync({ prefix: 'query_test_', keep: false, unsafeCleanup: true });
@@ -106,7 +105,7 @@ describe('using the new query server', function() {
106105
cliServer = extension.cliServer;
107106

108107
cliServer.quiet = true;
109-
if (!(await cliServer.cliConstraints.supportsNewQueryServer())) {
108+
if (!(await cliServer.cliConstraints.supportsNewQueryServerForTests())) {
110109
this.ctx.skip();
111110
}
112111
qs = new QueryServerClient({

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/run-remote-query.test.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ describe('Remote queries', function() {
100100
const querySubmissionResult = await runRemoteQuery(cli, credentials, fileUri, true, progress, cancellationTokenSource.token, variantAnalysisManager);
101101
expect(querySubmissionResult).to.be.ok;
102102
const queryPackRootDir = querySubmissionResult!.queryDirPath!;
103-
printDirectoryContents(queryPackRootDir);
104103

105104
// to retrieve the list of repositories
106105
expect(showQuickPickSpy).to.have.been.calledOnce;
@@ -113,7 +112,6 @@ describe('Remote queries', function() {
113112
expect(fs.readdirSync(queryPackRootDir).find(f => f.startsWith('qlpack-') && f.endsWith('-generated.tgz'))).not.to.be.undefined;
114113

115114
const queryPackDir = path.join(queryPackRootDir, 'query-pack');
116-
printDirectoryContents(queryPackDir);
117115

118116
expect(fs.existsSync(path.join(queryPackDir, 'in-pack.ql'))).to.be.true;
119117
expect(fs.existsSync(path.join(queryPackDir, 'lib.qll'))).to.be.true;
@@ -128,7 +126,6 @@ describe('Remote queries', function() {
128126

129127
// the compiled pack
130128
const compiledPackDir = path.join(queryPackDir, '.codeql/pack/codeql-remote/query/0.0.0/');
131-
printDirectoryContents(compiledPackDir);
132129

133130
expect(fs.existsSync(path.join(compiledPackDir, 'in-pack.ql'))).to.be.true;
134131
expect(fs.existsSync(path.join(compiledPackDir, 'lib.qll'))).to.be.true;
@@ -171,11 +168,9 @@ describe('Remote queries', function() {
171168
// check a few files that we know should exist and others that we know should not
172169

173170
// the tarball to deliver to the server
174-
printDirectoryContents(queryPackRootDir);
175171
expect(fs.readdirSync(queryPackRootDir).find(f => f.startsWith('qlpack-') && f.endsWith('-generated.tgz'))).not.to.be.undefined;
176172

177173
const queryPackDir = path.join(queryPackRootDir, 'query-pack');
178-
printDirectoryContents(queryPackDir);
179174

180175
expect(fs.existsSync(path.join(queryPackDir, 'in-pack.ql'))).to.be.true;
181176
expect(fs.existsSync(path.join(queryPackDir, 'qlpack.yml'))).to.be.true;
@@ -189,7 +184,6 @@ describe('Remote queries', function() {
189184

190185
// the compiled pack
191186
const compiledPackDir = path.join(queryPackDir, '.codeql/pack/codeql-remote/query/0.0.0/');
192-
printDirectoryContents(compiledPackDir);
193187
expect(fs.existsSync(path.join(compiledPackDir, 'in-pack.ql'))).to.be.true;
194188
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
195189
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'in-pack.ql', '0.0.0', await pathSerializationBroken());
@@ -208,7 +202,6 @@ describe('Remote queries', function() {
208202
expect(qlpackContents.dependencies?.['codeql/javascript-all']).to.equal('*');
209203

210204
const libraryDir = path.join(compiledPackDir, '.codeql/libraries/codeql');
211-
printDirectoryContents(libraryDir);
212205
const packNames = fs.readdirSync(libraryDir).sort();
213206

214207
// check dependencies.
@@ -233,11 +226,9 @@ describe('Remote queries', function() {
233226
// check a few files that we know should exist and others that we know should not
234227

235228
// the tarball to deliver to the server
236-
printDirectoryContents(queryPackRootDir);
237229
expect(fs.readdirSync(queryPackRootDir).find(f => f.startsWith('qlpack-') && f.endsWith('-generated.tgz'))).not.to.be.undefined;
238230

239231
const queryPackDir = path.join(queryPackRootDir, 'query-pack');
240-
printDirectoryContents(queryPackDir);
241232

242233
expect(fs.existsSync(path.join(queryPackDir, 'subfolder/in-pack.ql'))).to.be.true;
243234
expect(fs.existsSync(path.join(queryPackDir, 'qlpack.yml'))).to.be.true;
@@ -251,7 +242,6 @@ describe('Remote queries', function() {
251242

252243
// the compiled pack
253244
const compiledPackDir = path.join(queryPackDir, '.codeql/pack/codeql-remote/query/0.0.0/');
254-
printDirectoryContents(compiledPackDir);
255245
expect(fs.existsSync(path.join(compiledPackDir, 'otherfolder/lib.qll'))).to.be.true;
256246
expect(fs.existsSync(path.join(compiledPackDir, 'subfolder/in-pack.ql'))).to.be.true;
257247
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
@@ -270,7 +260,6 @@ describe('Remote queries', function() {
270260
expect(qlpackContents.dependencies?.['codeql/javascript-all']).to.equal('*');
271261

272262
const libraryDir = path.join(compiledPackDir, '.codeql/libraries/codeql');
273-
printDirectoryContents(libraryDir);
274263
const packNames = fs.readdirSync(libraryDir).sort();
275264

276265
// check dependencies.
@@ -399,12 +388,4 @@ describe('Remote queries', function() {
399388
function getFile(file: string): Uri {
400389
return Uri.file(path.join(baseDir, file));
401390
}
402-
403-
function printDirectoryContents(dir: string) {
404-
console.log(`DIR ${dir}`);
405-
if (!fs.existsSync(dir)) {
406-
console.log(`DIR ${dir} does not exist`);
407-
}
408-
fs.readdirSync(dir).sort().forEach(f => console.log(` ${f}`));
409-
}
410391
});

extensions/ql-vscode/src/vscode-tests/ensureCli.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ import { workspace } from 'vscode';
3030
* exists. And the cli will not be re-downloaded if the zip already exists.
3131
*/
3232

33-
process.on('unhandledRejection', e => {
34-
console.error('Unhandled rejection.');
35-
console.error(e);
36-
// Must use a setTimeout in order to ensure the log is fully flushed before exiting
37-
setTimeout(() => {
38-
process.exit(-1);
39-
}, 2000);
40-
});
41-
4233
const _1MB = 1024 * 1024;
4334
const _10MB = _1MB * 10;
4435

extensions/ql-vscode/src/vscode-tests/index-template.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ process.on('unhandledRejection', e => {
1616
}, 2000);
1717
});
1818

19+
process.on('exit', code => {
20+
// If the exit code is 7, then the test runner has completed, but
21+
// there was an error in exiting vscode.
22+
if (code === 7) {
23+
console.warn('Attempted to exit with code 7. This is likely due to a failure to exit vscode. Ignoring this and exiting with code 0.');
24+
process.exit(0);
25+
}
26+
});
27+
1928
/**
2029
* Helper function that runs all Mocha tests found in the
2130
* given test root directory.

extensions/ql-vscode/src/vscode-tests/minimal-workspace/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,3 @@ chai.use(sinonChai);
1313
export function run(): Promise<void> {
1414
return runTestsInDirectory(__dirname);
1515
}
16-
17-
process.addListener('unhandledRejection', (reason) => {
18-
if (reason instanceof Error && reason.message === 'Canceled') {
19-
console.log('Cancellation requested after the test has ended.');
20-
process.exit(0);
21-
} else {
22-
fail(String(reason));
23-
}
24-
});

0 commit comments

Comments
 (0)