condition-based-waiting

Replace arbitrary timeouts with condition polling to stabilize flaky tests.

Updated Dec 9, 2025
One-click install
npx skills add https://github.com/h4v1d/extension-collection-geminicli --skill condition-based-waiting-h4v1d
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: condition-based-waiting
Source: https://github.com/h4v1d/extension-collection-geminicli/tree/main/condition-based-waiting
Command: npx skills add https://github.com/h4v1d/extension-collection-geminicli --skill condition-based-waiting-h4v1d

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates flaky tests by replacing arbitrary timeouts with condition polling to wait for actual state changes.

Core Features & Use Cases

  • Deterministic waiting: replace fixed delays with polling until a real state is observed.
  • Avoid flaky behavior in tests and debugging workflows involving async operations.
  • Use in CI and local development to stabilize test runs and debugging sessions.

Quick Start

Use the waitFor utility to poll for a condition to become true in your tests, for example await waitFor(() => testRunner.state === 'ready').

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 asynchronous operations?

Use condition polling to wait for actual state changes instead of arbitrary timeouts. A generic waitFor utility polls a condition function at 10ms intervals until it resolves or times out, stabilizing asynchronous test runs.

What is condition polling and how does it prevent race conditions in testing?

Condition polling prevents race conditions by continuously checking a state predicate until it passes. It avoids fixed delays by actively waiting for real state changes, ensuring deterministic test outcomes.

How do I implement deterministic waiting for parallel execution in CI?

Implement deterministic waiting in CI by polling for a condition to become true using a generic waitFor utility. It checks state changes at 10ms intervals with a 5000ms timeout, eliminating nondeterministic parallel execution failures.

Can I replace fixed delays with a waitFor utility for local debugging workflows?

Yes, you can replace fixed delays with a waitFor utility for local debugging workflows. It polls a condition function at 10ms intervals up to a 5000ms timeout, waiting for actual state changes to stabilize debugging sessions.

What are the default timeout and polling intervals for condition-based waiting?

The default timeout is 5000ms and the polling interval is 10ms. These settings allow the waitFor utility to efficiently check for state changes without introducing long arbitrary delays in your test suite.

When should I avoid using condition polling in my test suite?

Avoid condition polling when operations complete instantly or lack a verifiable state change. Polling adds overhead, so if tests are purely synchronous or state cannot be observed, fixed delays or direct assertions may be more appropriate.