Test Flakiness Retry Budget
Plan test retry budget based on flakiness and CI costs. Enter values for instant results with step-by-step formulas.
Formula
Suite Confidence = (1 - Flake Rate^(Retries+1))^Flaky Tests ร 100%; Retry Overhead = (Expected Retries ร Avg Duration) / Base Duration ร 100%
Suite confidence calculates the probability that no flaky test causes a false failure. For each flaky test, the probability of passing with N retries is (1 - FlakeRate^(N+1)), since the test must fail N+1 consecutive times to ultimately fail. This probability is raised to the power of the number of flaky tests, since all must pass for the suite to pass. Retry overhead measures the additional time spent on retries as a percentage of base test time. This formula works because flaky failures are typically independent events, making the compound probability calculation valid. The exponential relationship explains why 2-3 retries capture most of the confidence benefit.
Worked Examples
Example 1: Small Test Suite Retry Planning
Problem:A team has 100 tests, 5% are flaky with 10% failure rate. They run CI 30 times/day at $0.01/min with 20-second average test time.
Solution:Configuration: Total tests: 100 Flaky tests: 5 (5%) Flake rate: 10% Max retries: 2 Probability analysis: Pass on first try: 90% Pass with 1 retry: 99% Pass with 2 retries: 99.9% Expected retries per flaky test: 0.10 + 0.01 = 0.11 retries Total expected retries: 5 ร 0.11 = 0.55 Time impact: Base run: 100 ร 20s = 2000s = 33.3 min Retry time: 0.55 ร 20s = 11s = 0.18 min Overhead: 0.5% Cost: Base: 33.3 ร $0.01 ร 30 = $10/day Retries: ~$0.05/day Monthly: ~$222
Result:2 retries optimal | 0.5% overhead | $222/month | 99.9% confidence
Example 2: High-Flakiness CI Pipeline
Problem:An e-commerce platform has 2000 tests, 12% flaky with 25% avg failure rate. 100 CI runs/day, $0.005/min, 45s avg test time.
Solution:Configuration: Total tests: 2000 Flaky tests: 240 (12%) Flake rate: 25% Max retries: 3 Probability: Pass on first: 75% Pass with 3 retries: 1 - 0.25โด = 99.6% Expected retries per flaky test: 0.25 + 0.0625 + 0.0156 = 0.33 Total: 240 ร 0.33 = 79 retries Time impact: Base: 2000 ร 45s = 90,000s = 1500 min Retries: 79 ร 45s = 3555s = 59 min Overhead: 4% Cost: Base: 1500 ร $0.005 ร 100 = $750/day Retries: 59 ร $0.005 ร 100 = $30/day Monthly: $17,160 โ ๏ธ 12% flakiness is high! Recommendation: Fix top 50 flakiest tests
Result:โ ๏ธ High flakiness | 4% overhead | $17K/month | Prioritize fixing tests
Example 3: Optimizing Retry Strategy
Problem:Compare retry strategies: 0, 1, 2, 3 retries for 500 tests, 8% flaky, 15% fail rate.
Solution:Scenario analysis at 50 runs/day: 0 Retries: - Suite pass rate: 52% (many false failures) - Cost: $550/month - Developer time wasted: High 1 Retry: - Suite pass rate: 93% - Overhead: 1.2% - Cost: $556/month - Improvement: 41% fewer false failures 2 Retries: - Suite pass rate: 98.9% - Overhead: 1.4% - Cost: $558/month - Improvement: 47% from baseline 3 Retries: - Suite pass rate: 99.8% - Overhead: 1.5% - Cost: $559/month - Marginal improvement: 0.9% Optimal: 2 retries Reason: 98.9% confidence at minimal extra cost 3rd retry adds little value for cost
Result:2 retries optimal | 98.9% confidence | $558/month | Diminishing returns at 3+
Frequently Asked Questions
What is test flakiness?
Test flakiness refers to tests that sometimes pass and sometimes fail without any code changes. Causes include timing issues, race conditions, test order dependencies, shared state, network variability, and environmental differences between runs.
How do retries help with flaky tests?
Retries give flaky tests additional chances to pass, reducing false failures. If a test has a 10% flake rate, one retry reduces the false failure rate to 1%, and two retries reduce it to 0.1%. However, retries add time and cost.
What's a good retry budget?
A good starting point is 2-3 retries for tests known to be flaky. The optimal budget balances confidence (reducing false failures) against cost (CI time and compute). Most teams find 2 retries sufficient for <15% flake rates.
Should I retry all tests or only flaky ones?
Best practice is to only retry known flaky tests. Retrying all tests wastes resources on stable tests and can mask real failures. Use historical data to identify and tag flaky tests for selective retries.
How do I measure test flakiness?
Track pass/fail results across multiple runs of the same code. A test that fails even once on unchanged code is flaky. Calculate flake rate as (inconsistent runs / total runs). Many CI systems provide built-in flakiness detection.
What causes test flakiness?
Common causes include: timing/async issues (race conditions, timeouts), test pollution (shared state, order dependency), external dependencies (network, databases, APIs), environment differences (timezone, locale), and resource constraints (memory, CPU).
Is it better to fix flaky tests or add retries?
Fixing root causes is always preferred long-term. Retries are a tactical solution that adds cost and hides underlying issues. Use retries as a temporary measure while prioritizing permanent fixes for high-impact flaky tests.
How much do retries cost?
Retry costs include CI compute time, delayed feedback, and engineering time investigating false failures. A test suite with 10% flaky tests and 2 retries might add 15-20% to CI costs. High-frequency CI pipelines amplify these costs.
How do retries affect build confidence?
Retries increase confidence that build failures represent real issues rather than flakiness. With properly configured retries, you can achieve 99%+ confidence that a failing build indicates actual problems, reducing wasted investigation time.
What is the 50/30/20 budget rule?
It allocates take-home pay into three buckets: 50% to needs, 30% to wants, and 20% to savings and debt repayment beyond minimum payments. Needs are the obligations that continue whether or not your circumstances change โ housing, utilities, groceries, insurance, transport to work, minimum debt payments. Wants are everything discretionary, including the subscriptions and dining out that most people misfile as necessities. The rule's value is not the specific percentages, which were never derived from research, but that it forces the savings share to be decided first rather than being whatever happens to survive the month. Treat it as a diagnostic: if needs alone exceed 50% of net pay, the problem is a fixed-cost problem and no amount of discretionary trimming will fix it.
Background & Theory
History
References
- Google Testing Blog: Flaky Tests at Google
- Microsoft Research: Test Flakiness Study
- CircleCI: Test Insights & Flaky Test Detection
- GitHub: Identifying Flaky Tests
- Spotify Engineering: Flaky Test Management
- Buildkite: Test Analytics
- Jest: Retry Configuration
- Martin Fowler: Eradicating Non-Determinism in Tests