测试与安全

Condition-Based Waiting

obra/superpowers-skills

Replace arbitrary timeouts with condition polling for reliable async tests

  • 0 次安装
  • 756 星标

安装命令

npx skills add https://github.com/obra/superpowers-skills --skill 'Condition-Based Waiting'

SKILL.md

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];