condition-based-waiting_skill

This skill helps you resolve race conditions in tests by waiting for actual conditions instead of fixed delays.
  • Python

0

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill chunkytortoise/enterprisehub --skill condition-based-waiting

  • SKILL.md13.8 KB

Overview

This skill provides practical, reusable patterns to eliminate race conditions and timing-related flakiness in tests. It focuses on replacing brittle fixed sleeps with condition-based waiting, and offers helpers for Redis, WebSockets, databases, file I/O, and service health checks. The goal is predictable tests that wait for actual readiness rather than arbitrary delays.

How this skill works

The skill supplies a small set of async wait-for-condition primitives and higher-level helpers that poll until a predicate becomes true or a timeout elapses. It integrates with test fixtures and retry decorators so you can wait for Redis pings, WebSocket handshakes, database records, file writes, or external HTTP health checks. Logging, environment-aware timeouts, and exponential backoff patterns make waits observable and configurable for local and CI environments.

When to use it

  • Intermittent test failures that pass on retry
  • Async tests with Redis connection timing issues
  • WebSocket connection handshakes and message ordering problems
  • Database transactions or eventual consistency delays
  • File system operations that complete asynchronously

Best practices

  • Replace fixed time.sleep calls with condition-based waiting and explicit timeouts
  • Tune timeouts per environment (local vs CI) and expose them via env vars
  • Log wait progress and reasons for timeouts to make failures actionable
  • Always close and clean up connections in fixtures to avoid cascading flakiness
  • Avoid infinite loops—use sensible poll intervals and overall timeouts

Example use cases

  • A pytest fixture that waits for Redis, Postgres, and an HTTP service before running integration tests
  • An async WebSocket test client that waits for handshake messages and content before asserting
  • A database helper that waits for a specific record to appear after a background job
  • A file-watcher test that waits for a file to exist and reach a minimum size or contain expected content
  • A retry decorator for flaky API calls with exponential backoff in test helpers

FAQ

Fixed sleeps mask the root cause, slow tests unnecessarily, and still can fail under load or CI variability. Condition-based waits only delay as long as needed and fail fast with diagnostic messages.

How do I choose poll intervals and timeouts?

Use short poll intervals (e.g. 0.05–0.2s) for responsiveness and set timeouts based on environment: smaller locally, larger in CI. Make them configurable via environment variables.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational