microsoft / microsoft/vscode-python-debugger

Race condition in `provider.unit.test.ts` due to slow initial execution

未关闭
#1,031 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

triage-needed
主要语言
TypeScript
星标
181
派生
126
平均合并
2 天 3 小时
30 天内合并 PR
3

描述

📝 Description

We are observing intermittent test failures during the first run of the unit tests, specifically within the AttachProcessProvider suite.

The root cause appears to be a Race Condition triggered by slow environment startup:

  1. First Test Timeout: The first test case (e.g., Linux process list) takes longer than 2000ms to resolve (likely due to initial module loading or environment lag), causing a Mocha timeout error.
  2. Polluted Assertions: While the second test is running, the asynchronous call from the first (timed-out) test finally completes.
  3. Double Call Error: This causes the sinon stub (like plainExec) to record an extra call during the second test's execution context, leading to an assertion failure: expected plainExec to be called once but it was called twice (or similar).
  586 passing (6s)
  27 pending
  2 failing
  1) Attach to process - process provider
       The Linux process list command should be called if the platform is Linux:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/vscode-python-debugger/vscode-python-debugger/testDir/out/test/unittest/attachQuickPick/provider.unit.test.js)
  	at listOnTimeout (node:internal/timers:585:17)
  	at process.processTimers (node:internal/timers:521:7)

  2) Attach to process - process provider
       The macOS process list command should be called if the platform is macOS:
     AssertError: expected plainExec to be called once and with exact arguments 
🛠 Steps to Reproduce
  1. Run tests in a resource-constrained environment (like a cold GitHub Actions runner or a slow local machine).
  2. Execute npm run test (or the equivalent test runner command).
  3. Observe that the first test fails with a timeout, and subsequent tests fail because stubs were called by the "ghost" of the previous failed test.
  4. Run the tests again immediately; observe that all tests (including the previously failed ones) now pass.

Environment: CI (GitHub Runner) https://github.com/ZA139/vscode-python-debugger/actions/runs/25676102630/job/75374288168 / Local Windows

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 provider.unit.test.ts 和 AttachProcessProvider suite 开始,然后在缓慢或冷启动的环境中运行 npm run test,以复现超时和后续的 stub 失败。完成的标准是 suite 中的第一个测试能够可靠地完成,并且 Linux 和 macOS 的断言通过,同时调用不会在测试之间泄漏。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
testing
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。