condition-based-waiting

Replace arbitrary timeouts with configurable condition polling in async tests.

146|31|Updated Jul 25, 2025
One-click install
npx skills add https://github.com/bobmatnyc/claude-mpm --skill condition-based-waiting-bobmatnyc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/bobmatnyc/claude-mpm/tree/main/src/claude_mpm/skills/bundled/testing/condition-based-waiting
Command: npx skills add https://github.com/bobmatnyc/claude-mpm --skill condition-based-waiting-bobmatnyc

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Replaces arbitrary timeouts with condition-based waiting to stabilize flaky tests.

Core Features & Use Cases

  • Generic waitFor helpers
  • Domain-specific waiting patterns
  • Improved reliability for async tests

Quick Start

  1. Identify arbitrary delays
  2. Implement waitFor pattern
  3. Validate with tests

Frequently Asked Questions about condition-based-waiting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace arbitrary timeouts with condition-based waiting in async tests?

Condition-based waiting replaces fixed delays with polling that checks for a specific condition before proceeding. Instead of `await sleep(5000)`, you evaluate a condition repeatedly until it's true or a timeout expires, eliminating race conditions and flaky timing dependencies in asynchronous tests.

What's the best way to handle race conditions and timing dependencies in tests?

Use condition polling to wait for events, state readiness, or resource availability instead of arbitrary delays. This approach reduces flakiness by allowing tests to proceed as soon as the actual condition is met, rather than waiting a fixed duration that may be too short or wastefully long.

Can I use polling patterns for waiting on specific events or state changes in tests?

Yes. Domain-specific helpers like waitForEvent, waitForEventCount, and waitForEventMatch provide targeted polling for common async test scenarios, allowing you to wait reliably for events to fire, accumulate to a threshold, or match expected criteria before assertions.

How do I identify where to apply condition-based waiting in my test suite?

Look for hardcoded `setTimeout` or `sleep` calls, tests that occasionally fail under load, or assertions that race against asynchronous operations. Replace those arbitrary delays with condition polling to stabilize flaky behavior and reduce test execution time.

What's the difference between timeout-based waiting and condition polling?

Timeout-based waiting pauses execution for a fixed duration regardless of whether the expected state has arrived. Condition polling checks repeatedly whether a condition is satisfied and proceeds immediately when true, making tests faster and more reliable without guessing required delay duration.

Do I need additional dependencies to implement the waitFor polling pattern?

The Skill provides a generic waitFor utility with configurable timeout and periodic condition evaluation built in, requiring no additional dependencies. It includes ready-to-use helpers for common patterns, making it self-contained for async test stabilization.