GitHub Actions Flaky Test Isolation Quick Snip

A deterministic workflow to isolate flaky tests in CI and convert random failures into reproducible local defects.

2 min read
#testing #reliability

Flaky tests are reliability debt that compounds silently across every merge. Treat them like production incidents: capture a signature, reproduce deterministically, classify the failure mode, then stabilize with clear ownership before the team normalizes random red builds as background noise.

Extract the Exact Failing Signature

@itsnas
main
# In CI logs, capture:
# - test name
# - stack trace
# - worker/shard
# - runtime and seed (if available)
main
Naseebullah
Ln 1, Col 1UTF-8

No signature, no diagnosis.

Reproduce Under CI-Like Constraints

@itsnas
main
CI=1 TZ=UTC pnpm test -- --runInBand
CI=1 TZ=UTC pnpm test -- --repeatEach=20
main
Naseebullah
Ln 1, Col 1UTF-8

Match environment and reduce nondeterminism.

Classify Failure Type

  • Timing/race: missing awaits, leaking async work
  • State bleed: shared global/module state
  • External dependency: clock/network/file-system assumptions
  • Order dependency: tests pass only in a specific sequence

Stabilize, Then Harden

@itsnas
main
# Prefer deterministic setup/teardown
# Replace sleep-based waits with explicit polling/assertions
main
Naseebullah
Ln 1, Col 1UTF-8

If a test is critical and still flaky, quarantine it temporarily with a tracked issue and owner.

Add Guardrails

  • Run failed suite repeatedly in CI nightly.
  • Alert when flake rate crosses threshold.
  • Fail PRs on newly introduced flaky signatures.

Copyright © 2025-present itsnas.me 
All Rights Reserved.