Commit 4c0689f
fix(mcp): kill zombie Mocha state when timeout fires before pause() (#5555)
* fix(mcp): kill zombie Mocha state when timeout fires before test reaches pause()
When run_test's timeout was shorter than the time the test needed to
reach pause() (e.g. 50ms timeout vs 30s Playwright helper timeout),
Mocha kept running in the background, eventually entered paused state
forever (because cancelRun had reset abortRun=false), and every
subsequent run_test threw "Mocha instance is currently running tests".
The only recovery was killing the MCP process.
Three changes:
- lib/codecept.js: capture the Runner returned by mocha.run() as
mocha.runner, so callers have a clean handle to abort. Previously
the return value was discarded.
- cancelRun(): call mocha.runner.abort() to actually stop Mocha (sets
the runner's _abort flag, makes the run callback fire fast). Drop
the 5s race against pendingRunPromise — with runner.abort() the
promise settles quickly; relying on a short race meant a 30s
Playwright step would outlive the cancel and Mocha state stayed
RUNNING.
- abortRun lifecycle: stop resetting it inside cancelRun. Reset it at
the start of each new run_test / run_step_by_step instead. This way
if a late pause() fires after cancelRun returns (test reached pause
asynchronously after the timeout), setPauseHandler still rejects it
instead of trapping forever.
Repro fixed:
run_test({timeout: 50}) → Timeout after 50ms
run_test({timeout: 60000}) → completed, stats: {tests:1, passes:1}
(was: second call permanently failed with "Mocha is already running")
Refs: testomatio/e2e-tests#103
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(mcp): drop paranoid container.mocha type guard
container.mocha is the static method on the Container class — always
callable. The typeof-check ternary was dead defensive code.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: DavertMik <davert@testomat.io>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8a1f081 commit 4c0689f
1 file changed
Lines changed: 2 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 63 | + | |
66 | 64 | | |
67 | 65 | | |
68 | 66 | | |
| |||
402 | 400 | | |
403 | 401 | | |
404 | 402 | | |
405 | | - | |
406 | | - | |
| 403 | + | |
407 | 404 | | |
408 | 405 | | |
409 | 406 | | |
| |||
0 commit comments