condition-based-waiting

Replace arbitrary test timeouts with polling-based waitFor condition checks.

205|26|Updated Oct 30, 2025
One-click install
npx skills add https://github.com/LerianStudio/ring --skill condition-based-waiting-lerianstudio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/LerianStudio/ring/tree/main/skills/condition-based-waiting
Command: npx skills add https://github.com/LerianStudio/ring --skill condition-based-waiting-lerianstudio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Arbitrary timeouts (setTimeout, sleep) in tests create race conditions, leading to flaky tests that pass inconsistently. This skill replaces guesses with reliable condition polling.

Core Features & Use Cases

  • Condition Polling: Replaces fixed delays with a generic waitFor function that polls for an actual state change.
  • Specific Helpers: Provides examples of domain-specific helpers like waitForEvent, waitForEventCount, and waitForEventMatch for common async scenarios.
  • Justified Arbitrary Timeouts: Defines strict requirements for when a fixed timeout is acceptable (e.g., testing actual timing behavior).

Quick Start

I have a flaky test with setTimeout. Use the condition-based-waiting skill to make it reliable.

Frequently Asked Questions about condition-based-waiting

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

FAQPage Schema
How do I fix flaky tests caused by arbitrary timeouts?

Replace fixed delays like setTimeout or sleep with condition polling. Use a waitFor function that checks for actual state changes at regular intervals instead of guessing how long an operation takes, eliminating race conditions that cause tests to pass inconsistently.

What's the best way to handle async operations in test code?

Wait for real conditions instead of arbitrary delays. Implement polling-based helpers like waitForEvent or waitForEventCount that verify the expected state has actually occurred, rather than sleeping and hoping the system is ready.

Can I use condition-based waiting with parallel or load-tested code?

Yes. Condition polling handles flaky tests under load and parallel execution by eliminating timing assumptions. Tests become reliable regardless of system speed or concurrent operations, since they wait for proven state changes, not elapsed time.

When should I stop using setTimeout in tests?

Use fixed timeouts only when testing actual timing behavior itself. For all other async scenarios—waiting for events, state changes, or API responses—condition polling is more reliable and maintainable than arbitrary sleep durations.

How does polling-based waiting improve test reliability?

Polling checks for conditions at 10ms intervals until they're met or a timeout expires. This approach catches state changes immediately rather than gambling on a fixed delay, preventing tests from failing on slow machines or under resource contention.