Skip to content
bobmatnyc avatar

Condition Based Waiting

Replace arbitrary test delays with condition polling so async tests stop failing under load.

CCM score
54 of 100
skills.sh installs
355
GitHub stars
79
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers the replacement of setTimeout, sleep, and time.sleep() delays with waits on real conditions
  • Includes a generic waitFor polling helper plus waitForEvent, waitForEventCount, and waitForEventMatch in example.ts
  • Enforces a timeout with a descriptive error and documents why any intentional fixed delay is needed
  • Designed for flaky or timing-dependent async tests that pass sometimes and fail under parallel or CI runs

Install

$ npx -y skills add bobmatnyc/claude-mpm-skills --skill 'Condition-Based Waiting' -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Condition-Based Waiting

Overview

Flaky tests often guess at timing with arbitrary delays. This creates race conditions where tests pass on fast machines but fail under load or in CI.

Core principle: Wait for the actual condition you care about, not a guess about how long it takes.

When to Use

digraph when_to_use {
    "Test uses setTimeout/sleep?" [shape=diamond];
    "Testing timing behavior?" [shape=diamond];
    "Document WHY timeout needed" [shape=box];
    "Use condition-based waiting" [shape=box];

    "Test uses setTimeout/sleep?" -> "Testing timing behavior?" [label="yes"];
    "Testing timing behavior?" -> "Document WHY timeout needed" [label="yes"];
    "Testing timing behavior?" -> "Use condition-based waiting" [label="no"];
}

Use when:

  • Tests have arbitrary delays (setTimeout, sleep, time.sleep())
  • Tests are flaky (pass sometimes, fail under load)
  • Tests timeout when run in parallel
  • Waiting for async operations to complete

Don't use when:

  • Testing actual timing behavior (debounce, throttle intervals)
  • Always document WHY if using arbitrary timeout

Core Pattern

Details

Repository
github.com/bobmatnyc/claude-mpm-skills
Categories
Testing & QA, Debugging
First seen
Jun 3, 2026

Questions

What does the Condition-Based Waiting skill do for flaky tests?

It replaces arbitrary timeouts such as setTimeout, sleep and time.sleep() with condition polling, so an async test waits for the actual result it needs. The skill says this fixes race conditions and timing dependencies that make tests pass on fast machines but fail under load or in CI.

How do I install the Condition-Based Waiting skill?

Run npx -y skills add bobmatnyc/claude-mpm-skills --skill 'Condition-Based Waiting' -y in your project. After installing, the agent can rewrite tests that use fixed delays into waitFor-style checks on the condition under test.

When should I use the Condition-Based Waiting skill?

Use it when tests have race conditions, timing dependencies, or inconsistent pass and fail behavior. It also fits tests that time out when run in parallel or that wait on asynchronous operations to finish.

Is Condition-Based Waiting suitable for testing debounce or throttle timing?

No, the skill says not to use it when you are testing actual timing behavior such as debounce or throttle intervals. In those cases it advises documenting why a fixed timeout is needed.

Which skills are alongside Condition-Based Waiting in the Testing & QA category?

Other skills in Testing & QA include tdd, migrate-to-shoehorn, test-driven-development, webapp-testing and break-ui. Condition-Based Waiting stands apart by focusing on replacing guessed delays with polling on the condition a test cares about.

More from bobmatnyc/claude-mpm-skills

All 154

Similar to Condition Based Waiting

More Testing & QA