Skip to content

Commit a3fafc8

Browse files
authored
Merge pull request #1611 from github/aeisenberg/fix-flakes
Test cleanups
2 parents 6a636ba + ccdffc2 commit a3fafc8

File tree

12 files changed

+78
-70
lines changed

12 files changed

+78
-70
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
env:
127127
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
128128
run: |
129-
sudo apt-get install xvfb
129+
unset DBUS_SESSION_BUS_ADDRESS
130130
/usr/bin/xvfb-run npm run integration
131131
132132
- name: Run integration tests (Windows)
@@ -193,6 +193,7 @@ jobs:
193193
working-directory: extensions/ql-vscode
194194
if: matrix.os == 'ubuntu-latest'
195195
run: |
196+
unset DBUS_SESSION_BUS_ADDRESS
196197
/usr/bin/xvfb-run npm run cli-integration
197198
198199
- 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
@@ -1338,7 +1338,7 @@ export class CliVersionConstraint {
13381338
/**
13391339
* CLI version that supports the new query server.
13401340
*/
1341-
public static CLI_VERSION_WITH_NEW_QUERY_SERVER = new SemVer('2.11.0');
1341+
public static CLI_VERSION_WITH_NEW_QUERY_SERVER = new SemVer('2.11.1');
13421342

13431343
constructor(private readonly cli: CodeQLCliServer) {
13441344
/**/
@@ -1423,8 +1423,11 @@ export class CliVersionConstraint {
14231423
async supportsNewQueryServer() {
14241424
// TODO while under development, users _must_ opt-in to the new query server
14251425
// by setting the `codeql.canaryQueryServer` setting to `true`.
1426-
// Ignore the version check for now.
1427-
return allowCanaryQueryServer();
1428-
// return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
1426+
return allowCanaryQueryServer() &&
1427+
this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
1428+
}
1429+
1430+
async supportsNewQueryServerForTests() {
1431+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NEW_QUERY_SERVER);
14291432
}
14301433
}

extensions/ql-vscode/src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ export const ALL_SETTINGS: Setting[] = [];
1010
export class Setting {
1111
name: string;
1212
parent?: Setting;
13+
private _hasChildren = false;
1314

1415
constructor(name: string, parent?: Setting) {
1516
this.name = name;
1617
this.parent = parent;
18+
if (parent !== undefined) {
19+
parent._hasChildren = true;
20+
}
1721
ALL_SETTINGS.push(this);
1822
}
1923

24+
get hasChildren() {
25+
return this._hasChildren;
26+
}
27+
2028
get qualifiedName(): string {
2129
if (this.parent === undefined) {
2230
return this.name;

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)