Skip to content

Commit 35e8ce1

Browse files
committed
Fix various test flakiness
This commit addresses various test flakiness: 1. Bump timeouts for queries tests 2. Add a dispose handler to queryserver-client. This will help us during tests because if there is a test that timesout while a query is running, the query's progress callback won't be invoked. We will still get a timeout error in the first test, but the second test will not get a spurious error. 3. Handle a disposed query server in `deregisterDatabase`. This method will remove the database from the currently running query server. If there is no query server, then there is nothing to remove. So, this error is safe to ignore. 4. Explicitly `end()` a connection `ServerProcess`. I'm not 100% sure if this is necessary, but it seems like it prevents responses from being handled and erroring out. 5. Better handling of ideServer restarts. Previously, if you quickly called `CodeQL: Restart Query Server` twice in a row, you would get an error from the ideServer restart. Restart fails if the server is not already started. So, in this case just call a start.
1 parent ffa643c commit 35e8ce1

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ function getCommands(
177177
cliServer.restartCliServer();
178178
await Promise.all([
179179
queryRunner.restartQueryServer(progress, token),
180-
ideServer.restart(),
180+
async () => {
181+
if (ideServer.isRunning()) {
182+
await ideServer.restart();
183+
} else {
184+
await ideServer.start();
185+
}
186+
},
181187
]);
182188
void showAndLogInformationMessage("CodeQL Query Server restarted.", {
183189
outputLogger: queryServerLogger,

extensions/ql-vscode/src/json-rpc-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class ServerProcess implements Disposable {
2323
dispose(): void {
2424
void this.logger.log(`Stopping ${this.name}...`);
2525
this.connection.dispose();
26+
this.connection.end();
2627
this.child.stdin!.end();
2728
this.child.stderr!.destroy();
2829
// TODO kill the process if it doesn't terminate after a certain time limit.

extensions/ql-vscode/src/local-databases.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,19 @@ export class DatabaseManager extends DisposableObject {
10221022
token: vscode.CancellationToken,
10231023
dbItem: DatabaseItem,
10241024
) {
1025-
await this.qs.deregisterDatabase(progress, token, dbItem);
1025+
try {
1026+
await this.qs.deregisterDatabase(progress, token, dbItem);
1027+
} catch (e) {
1028+
const message = getErrorMessage(e);
1029+
if (message === "Connection is disposed.") {
1030+
// This is expected if the query server is not running.
1031+
void extLogger.log(
1032+
`Could not de-register database '${dbItem.name}' because query server is not running.`,
1033+
);
1034+
return;
1035+
}
1036+
throw e;
1037+
}
10261038
}
10271039
private async registerDatabase(
10281040
progress: ProgressCallback,

extensions/ql-vscode/src/query-server/queryserver-client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ensureFile } from "fs-extra";
22

3-
import { DisposableObject } from "../pure/disposable-object";
3+
import { DisposableObject, DisposeHandler } from "../pure/disposable-object";
44
import { CancellationToken } from "vscode";
55
import { createMessageConnection, RequestType } from "vscode-jsonrpc/node";
66
import * as cli from "../cli";
@@ -224,4 +224,10 @@ export class QueryServerClient extends DisposableObject {
224224
delete this.progressCallbacks[id];
225225
}
226226
}
227+
228+
public dispose(disposeHandler?: DisposeHandler | undefined): void {
229+
this.progressCallbacks = {};
230+
this.stopQueryServer();
231+
super.dispose(disposeHandler);
232+
}
227233
}

extensions/ql-vscode/test/vscode-tests/cli-integration/queries.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { AllCommands, QueryServerCommands } from "../../../src/common/commands";
3030
/**
3131
* Integration tests for queries
3232
*/
33+
jest.setTimeout(60_000);
3334
describeWithCodeQL()("Queries", () => {
3435
let dbItem: DatabaseItem;
3536
let databaseManager: DatabaseManager;

0 commit comments

Comments
 (0)