From 6d15f3704dfeb2bdb094fd2864c5a2dd3ed0e42c Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Mon, 2 Feb 2026 14:38:09 -0800 Subject: [PATCH] Fix flaky activation test by polling instead of fixed delay The activation test was failing intermittently on Windows CI because it used a hardcoded 4-second delay after opening a .ql file to wait for the extension to activate. On slower machines, this wasn't enough time. Replace the fixed delay with a polling loop that checks ext.isActive every 100ms for up to 30 seconds. This ensures the test: - Returns quickly on fast machines - Doesn't fail prematurely on slow machines --- .../minimal-workspace/activation.test.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/activation.test.ts b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/activation.test.ts index 89fff4bd959..f77c29642a5 100644 --- a/extensions/ql-vscode/test/vscode-tests/minimal-workspace/activation.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/minimal-workspace/activation.test.ts @@ -1,4 +1,5 @@ import { resolve } from "path"; +import type { Extension } from "vscode"; import { extensions, workspace } from "vscode"; import { run } from "./local-queries/determining-selected-query-test"; @@ -16,21 +17,29 @@ describe("launching with a minimal workspace", () => { }); it("should activate the extension when a .ql file is opened", async () => { - await delay(); - const folders = workspace.workspaceFolders; expect(folders?.length).toEqual(1); const folderPath = folders![0].uri.fsPath; const documentPath = resolve(folderPath, "query.ql"); const document = await workspace.openTextDocument(documentPath); expect(document.languageId).toEqual("ql"); - // Delay slightly so that the extension has time to activate. - await delay(); + // Wait for the extension to activate, polling with a timeout. + await waitForActivation(ext!, 30_000); expect(ext!.isActive).toBeTruthy(); }, 60_000); - async function delay() { - await new Promise((resolve) => setTimeout(resolve, 4000)); + async function waitForActivation( + extension: Extension, + timeoutMs: number, + ): Promise { + const pollIntervalMs = 100; + const maxAttempts = Math.ceil(timeoutMs / pollIntervalMs); + for (let i = 0; i < maxAttempts; i++) { + if (extension.isActive) { + return; + } + await new Promise((resolve) => setTimeout(resolve, pollIntervalMs)); + } } });