aglinxinyuan opened a new issue, #9197:
URL: https://github.com/apache/texera/issues/9197

   ### What happened?
   
   The `build / frontend (macos-latest, 24.19.0)` leg fails at random on `main` 
with a unit-test timeout in whichever spec happens to be running. For example, 
in [run 
40411028530](https://github.com/apache/texera/actions/runs/40411028530/job/121881547223),
 a synchronous `beforeEach` in `computing-unit-actions.service.spec.ts` hit the 
30 s hook timeout, and the other 6852 tests passed. When the leg does pass, its 
Vitest run still takes 250–950 s. The ubuntu leg runs the same suite in 100–150 
s.
   
   The cause is memory that grows across spec files inside each Vitest worker. 
The Angular unit-test builder runs Vitest with `isolate: false`. On the 3-vCPU 
/ 7 GB macOS runner that means 2 workers, each running about 120 spec files one 
after another against one jsdom document and one copy of Vitest. A finished 
test's TestBed graph (component tree, root injector, NgZone, services) can only 
be freed if nothing worker-wide still points into it. Several things do, and 
any one of them is enough to keep the graph alive:
   
   - **Root services that never release what they start.**
     - `WorkflowActionService`: its shared model's y-websocket provider keeps a 
check interval, a BroadcastChannel subscription and doc listeners. 
`SharedModel.destroy()` only calls `disconnect()`, and only when the provider 
is connected.
     - `WorkflowWebsocketService`: its heartbeat `interval()` is never 
unsubscribed.
     - `JupyterPanelService`: its `window` `message` listener is never removed.
   - **jsdom's selector cache (nwsapi).** It memoizes every selector together 
with the nodes it matched, including the fresh `#root<N>` query TestBed makes 
for each fixture.
   - **Vitest 4's mock registry (`@vitest/spy`).** It is a strong `Set` that is 
never pruned, so every `vi.fn()` / `vi.spyOn()` of the run stays alive with 
what it recorded or spied on. Vitest 5 holds mocks weakly, but Angular 21's 
builder still requires Vitest 4.
   
   Measured locally in the CI shape (2 workers, coverage on):
   - Each worker's live heap after GC climbs to about 2.1–2.4 GB by the end of 
the run.
   - The whole process tree peaks at 8.7–9.0 GB of physical footprint, more 
than the runner has.
   
   The VM then swaps and stalls for tens of seconds. Vitest checks a timeout 
only after the hook or test returns, so a stall that long fails whatever test 
is running. That's why the failing spec changes from run to run, and why 
raising the timeouts (#7713) or the worker heap cap (#7975) only moved the 
problem.
   
   Expected: per-worker memory stays bounded, so the macOS leg runs at about 
the ubuntu pace without random timeouts.
   
   ### How to reproduce?
   
   1. On macOS, run the CI command with the macOS runner's worker count:
   
      ```
      VITEST_MAX_WORKERS=2 yarn --cwd frontend run test:ci
      ```
   
   2. Watch the two Vitest worker processes (Activity Monitor, or `ps -o rss`). 
Their memory keeps growing for the whole run instead of levelling off.
   
   On the GitHub macOS runner the same growth shows up as intermittent timeouts 
in unrelated specs.
   
   ### Version/Branch
   
   1.4.0-incubating-SNAPSHOT (main)
   
   ### Commit Hash (Optional)
   
   2ba75f482b4218b4a1ce0432292355c540cbb2b8
   
   ### Relevant log output
   
   ```shell
    FAIL   gui  
src/app/common/service/computing-unit/computing-unit-actions/computing-unit-actions.service.spec.ts
 > ComputingUnitActionsService > confirmAndTerminate > uses the disconnect 
wording and shows no destructive warning for a local unit
   Error: Hook timed out in 30000ms.
    Test Files  1 failed | 242 passed (243)
         Tests  1 failed | 6852 passed | 1 skipped (6854)
      Duration  740.66s (transform 40.85s, setup 97.81s, import 137.17s, tests 
787.10s, environment 216.27s)
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to