Skip to content

Add Support for Backoff Mechanism in Retry Configuration #8095

@denbon05

Description

@denbon05

Clear and concise description of the problem

Vitest's retry option re-runs failed tests but lacks a configurable backoff strategy. Specifically, when testing against rate-limited APIs.

  1. Exceeding Rate Limits: Immediate retries often hit rate limits again, sending rapid, failing requests.
  2. API Blocking: Continuous retries can cause APIs to throttle or block further requests.
  3. Increased Test Run Time: Tests fail quickly without giving the API time to recover, especially problematic with shared database instances.

This limits the effectiveness of integration tests against external services, as transient network issues or API rate limits are not gracefully handled.

Suggested solution

Extend the retry configuration to include a configurable backoff strategy. This would allow Vitest to wait between retries, giving external services time to recover.

Benefits of this solution:

  1. Graceful API Interaction: Reduces load on rate-limited APIs, allowing recovery.
  2. Improved Test Reliability: Increases the chance of flaky tests passing due to temporary external service issues.
  3. Reduced API Abuse: Prevents accidental denial-of-service during test runs.
  4. Flexibility: Users can fine-tune the backoff strategy for specific API characteristics.

Alternative

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    // Existing retry count
    retry: 3, 
    
    // New backoff configuration
    retryBackoff: {
      initialInterval: 1000, // Initial delay in ms (e.g., 1 second)
      maxInterval: 15000,    // Maximum delay in ms (e.g., 15 seconds)
      exponent: 2,           // Factor for interval increase (e.g., exponential backoff)
    },
    // ... other test options
  },
});

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions