From 067d244621996f20a817e9954527dafb4d15a630 Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Fri, 30 Jan 2026 09:09:41 -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 | 20 +++++++++++++------ 1 file changed, 14 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..029e8514c95 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 @@ -16,21 +16,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: typeof ext, + timeoutMs: number, + ): Promise { + const pollIntervalMs = 100; + const maxAttempts = timeoutMs / pollIntervalMs; + for (let i = 0; i < maxAttempts; i++) { + if (extension!.isActive) { + return; + } + await new Promise((resolve) => setTimeout(resolve, pollIntervalMs)); + } } });