patternMajorpending
CI pipeline flaky due to test ordering or shared state
Viewed 0 times
flaky testtest isolationshared statetest orderingrace conditionbeforeEach
ci-cdnodejs
Error Messages
Problem
Tests pass locally but fail intermittently in CI. Some tests pass individually but fail when run together. Failures are not reproducible consistently.
Solution
Common causes: (1) Tests share mutable state (database, files, global variables) — use beforeEach/afterEach to reset state. (2) Tests depend on execution order — randomize test order to expose this (Jest: --randomize, pytest: pytest-randomly). (3) Async operations leaking between tests — use fake timers and await all promises. (4) Port conflicts — use random ports in tests. (5) Time-dependent tests — mock Date.now() and timers. (6) Resource contention — CI has fewer CPU cores, causing race conditions that don't appear locally.
Why
Local machines are faster and often run tests in the same order. CI environments have different timing, parallelism, and isolation characteristics that expose hidden dependencies.
Revisions (0)
No revisions yet.