Skip to content

Fix race condition in VS Code debugger integration tests #2649

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

Merged
merged 1 commit into from
Aug 9, 2025

Conversation

minestarks
Copy link
Member

Fixed a race condition in the Q# and OpenQASM debugger integration tests that was causing intermittent test failures.

Problem:

  • Tests were racing with VS Code's automatic debugger state requests
  • When the debugger paused, both the test code and VS Code would send scopes and variables requests
  • Depending on timing, tests could receive responses to VS Code's requests instead of their own
  • This resulted in reading variables from the wrong stack frame and assertion failures

Changes:

  • Modified test logic: Tests now wait for debugger pause state before making their own requests
  • Improved request tracking: Added waitUntilResponse() method to track specific command responses
  • Dynamic variable references: Tests now dynamically retrieve variable references from scopes responses instead of using hardcoded values
  • Consolidated wait methods: Refactored waitUntilPausedAndAssertStackTrace() and waitUntilPausedAndAssertVariables() into a single waitUntilPaused() method with options
  • Enhanced tracker state management: Added proper request-response pair tracking with sequence numbers

The fix ensures tests consistently read variables from the correct stack frame by waiting for their own requests to complete rather than potentially intercepting VS Code's internal debugger communication.

Examples (VS Code's requests in purple, our test's requests in red):

Before, bad run:

image

VS Code comes in with the variables request, the variablesReference changes from 1003 to 1006, and our request ends up using the wrong id (and the test potentially uses the wron response object too)

Before, good run:

image

We intercepted VS Code, so the variablesReference 1003 happened to work

Fixed:

image

We waited until the debugger was paused and VS Code was out of the way, and then sent a scopes request to get the proper variablesReference to call with.

Copy link
Contributor

@orpuente-MS orpuente-MS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am glad you fixed the hard coded variable reference! Thanks!

@minestarks minestarks added this pull request to the merge queue Aug 8, 2025
Merged via the queue into main with commit 3683f7a Aug 9, 2025
18 checks passed
@minestarks minestarks deleted the minestarks/debugger-race branch August 9, 2025 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants