-
Notifications
You must be signed in to change notification settings - Fork 222
Fix flaky activation test by polling instead of fixed delay #4283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a flaky activation test that was failing intermittently on Windows CI by replacing a hardcoded 4-second delay with a polling approach that checks for extension activation up to 30 seconds.
Changes:
- Replaced fixed
delay()calls with a newwaitForActivation()function that polls extension status - Implemented polling logic with 100ms intervals and 30-second timeout
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return; | ||
| } | ||
| await new Promise((resolve) => setTimeout(resolve, pollIntervalMs)); | ||
| } |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The waitForActivation function should throw an error if the extension fails to activate within the timeout period. Currently, if the timeout is reached without activation, the function returns silently, and the test will fail on the subsequent assertion at line 27 with a less informative error message. Consider throwing a descriptive error after the loop completes to make timeout failures clearer and easier to diagnose.
| } | |
| } | |
| throw new Error( | |
| `Extension "GitHub.vscode-codeql" did not activate within ${timeoutMs} ms.`, | |
| ); |
| const pollIntervalMs = 100; | ||
| const maxAttempts = timeoutMs / pollIntervalMs; | ||
| for (let i = 0; i < maxAttempts; i++) { | ||
| if (extension!.isActive) { |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-null assertion operator on 'extension' (line 37) assumes the parameter is always defined, but the parameter type 'typeof ext' can be 'Extension | undefined'. Consider adding a check at the beginning of the function to validate that extension is defined, or update the function signature to ensure extension cannot be undefined.
| const pollIntervalMs = 100; | |
| const maxAttempts = timeoutMs / pollIntervalMs; | |
| for (let i = 0; i < maxAttempts; i++) { | |
| if (extension!.isActive) { | |
| if (!extension) { | |
| throw new Error("Extension is not defined."); | |
| } | |
| const pollIntervalMs = 100; | |
| const maxAttempts = timeoutMs / pollIntervalMs; | |
| for (let i = 0; i < maxAttempts; i++) { | |
| if (extension.isActive) { |
| timeoutMs: number, | ||
| ): Promise<void> { | ||
| const pollIntervalMs = 100; | ||
| const maxAttempts = timeoutMs / pollIntervalMs; |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation 'timeoutMs / pollIntervalMs' on line 35 may result in a non-integer value if timeoutMs is not evenly divisible by pollIntervalMs. While the for loop will handle this by truncating to an integer, it means the actual timeout may be shorter than intended. Consider using 'Math.ceil(timeoutMs / pollIntervalMs)' to ensure the full timeout duration is respected.
| const maxAttempts = timeoutMs / pollIntervalMs; | |
| const maxAttempts = Math.ceil(timeoutMs / pollIntervalMs); |
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: