architecting-systems
Guides clean, scalable system architecture during the build phase. Use when designing modules, defining boundaries, structuring…
Diagnose and fix tests that pass in isolation but fail when run concurrently. Covers shared state isolation, resource conflicts, and timing-based flakiness.
$ npx -y skills add rileyhilliard/claude-essentials --skill fixing-flaky-tests --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/fixing-flaky-testsContext preview
The summary Claude sees to decide when to auto-load this skill.
Diagnose and fix tests that pass in isolation but fail when run concurrently. Covers shared state isolation, resource conflicts, and timing-based flakiness.
name: fixing-flaky-tests description: Diagnose and fix tests that pass in isolation but fail when run concurrently. Covers shared state isolation, resource conflicts, and timing-based flakiness.
If the current repo has its own rules/skills covering this topic (check .claude/rules/ and repo CLAUDE.md), those take precedence — apply this skill only where they're silent.
**Target symptom:** Tests pass when run alone, fail when run with other tests.
Test passes alone, fails with others?
│
├─ Same error every time → Shared state
│ └─ Database, globals, files, singletons
│
├─ Random/timing failures → Race condition
│ └─ See async waiting patterns in `writing-tests` skill
│
└─ Resource errors (port, file lock) → Resource conflict
└─ Need unique resources per test/worker**Quick diagnosis:** 1. Run failing test 10x alone - does it always pass? 2. Run failing test 10x with the suite - same error or different? 3. Check error message - mentions port/file/connection?
Tests pollute state that other tests depend on. Fix by isolating state per test.
| State Type | Isolation Pattern | |------------|-------------------| | **Database** | Transaction rollback, savepoints, worker-specific DBs | | **Global variables** | Reset in `beforeEach`/`afterEach` | | **Singletons** | Provide fresh instance per test | | **Module state** | `jest.resetModules()` or equivalent | | **Files** | Unique paths per test, temp directories | | **Environment vars** | Save/restore in setup/teardown |
**Database isolation (most common):**
# Python: Savepoint rollback - each test gets rolled back
@pytest.fixture
async def db_session(db_engine):
async with db_engine.connect() as conn:
await conn.begin()
await conn.begin_nested() # Savepoint
# ... yield session ...
await conn.rollback() # All changes vanish// Jest: Reset mocks between tests
beforeEach(() => {
jest.clearAllMocks()
jest.resetModules() // Clear module cache before test
})
afterEach(() => {
jest.restoreAllMocks() // Restore spied functions
})See language-specific references for complete patterns.
Tests don't wait for async operations to complete.
**See the `writing-tests` skill** for async waiting patterns:
**Quick summary:** Wait for conditions, not time:
// Bad
await sleep(500)
// Good
await waitFor(() => expect(result).toBe('done'))Multiple tests or workers compete for same resource.
**Worker-specific resources:**
# Python pytest-xdist: unique DB per worker
@pytest.fixture(scope="session")
def database_url(worker_id):
if worker_id == "master":
return "postgresql://localhost/test"
return f"postgresql://localhost/test_{worker_id}"// Jest/Node: dynamic port allocation const server = app.listen(0) // OS assigns available port const port = server.address().port
**File conflicts:**
import tempfile
@pytest.fixture
def temp_dir():
with tempfile.TemporaryDirectory() as d:
yield d| Stack | Reference | |-------|-----------| | Python (pytest, SQLAlchemy) | [references/python.md](references/python.md) | | Jest / Testing Library | [references/jest.md](references/jest.md) | | Playwright E2E | [references/playwright.md](references/playwright.md) | | Async waiting patterns (TypeScript) | [writing-tests waiting-typescript](../writing-tests/references/waiting-typescript.md) | | Async waiting patterns (Python) | [writing-tests waiting-python](../writing-tests/references/waiting-python.md) |
After fixing, verify the fix worked:
# Run the specific test many times pytest tests/test_flaky.py -x --count=20 # Run with parallelism pytest -n auto # Jest equivalent jest --runInBand # First verify serial works jest # Then verify parallel works
A unified development plugin for Claude Code with essential skills and specialized agents, all accessible under the ce namespace.
Guides clean, scalable system architecture during the build phase. Use when designing modules, defining boundaries, structuring…
Enforces precise, minimal design for dashboards and admin interfaces. Use when building SaaS UIs, data-heavy interfaces, or any…
Executes implementation plans directly with a verification gate and conditional code review. Use when carrying out a written plan…
Prevents silent failures and context loss in error handling. Use when writing try-catch blocks, designing error propagation,…
Guides database architecture for PostgreSQL, DuckDB, Parquet, PGVector, and Neo4j. Use when designing schemas, choosing storage…
Guides GitHub Actions CI/CD architecture, security hardening, and deployment strategies. Use when designing workflows, securing…