Skip to main content

Module loadtest

Module loadtest 

Source
Expand description

Load testing utilities for stress testing request handlers.

Provides a configurable load generator that spawns concurrent request tasks and collects latency/error statistics.

§Example

use fastapi_core::loadtest::{LoadTest, LoadTestConfig, LoadTestReport};
use std::time::Duration;

let config = LoadTestConfig::new()
    .total_requests(1000)
    .concurrency(10);

let report = LoadTest::run(&config, |i| {
    // Simulate request work (return Ok for success, Err for failure)
    if i % 100 == 99 { Err("simulated error".into()) } else { Ok(()) }
});

assert!(report.success_rate() > 0.95);
println!("{report}");

Structs§

LoadTest
Load test runner.
LoadTestConfig
Configuration for a load test.
LoadTestReport
Report from a completed load test.