Repeat is a powerful command-line utility designed to execute a command repeatedly until a specific condition is met. It is perfect for stress testing, monitoring, debugging flaky scripts, or simply running a task multiple times.
- Iteration Control: Specify the exact number of times to run a command.
- Conditional Stopping: Stop execution based on:
- A specific exit code.
- A specific output string (stdout).
- Environment Variables: Pass custom environment variables to the command.
- Timeouts: Enforce time limits for individual runs and the entire execution process.
- Delays: Add fixed or random delays before the first run or between iterations.
- Analysis: JSON output for easy parsing and analysis of execution metrics.
To install repeat, ensure you have Rust and Cargo installed, then run:
cargo install --path .repeat [OPTIONS] <COMMAND>...<COMMAND>...: The command and its arguments to execute repeatedly.
-i, --iterations <ITERATIONS>: Number of iterations to run (default: 10).--exit-code <CODE>: Stop repeating if the command returns this specific exit code.--match-output <STRING>: Stop repeating if the command's standard output matches this string.--env <KEY=VALUE>: Set environment variables for the command (can be specified multiple times).--single-run-timeout-sec <SECS>: Maximum time (in seconds) allowed for a single execution (default: 10).--total-run-timeout-sec <SECS>: Maximum time (in seconds) allowed for the entire operation (default: 100).--initial-delay <SECS>: Delay (in seconds) before starting the first execution. Supports fixed values (e.g.,5) or ranges (e.g.,1..5).--in-between-delay <SECS>: Delay (in seconds) between executions. Supports fixed values (e.g.,2) or ranges (e.g.,1..3).-v, --verbose: Enable verbose logging.
Run a command 10 times (default):
repeat echo "Hello World"Run a command 5 times:
repeat --iterations 5 echo "Hello World"Or using the short form:
repeat -i 5 echo "Hello World"Run a script until it fails (returns exit code 1):
repeat --exit-code 1 ./flaky-test.shRun a script until it succeeds (returns exit code 0):
repeat --exit-code 0 ./deployment-check.shRun a command until it outputs "Ready":
repeat --match-output "Ready" ./check-service-status.shWait for a server to start:
repeat --match-output "Server listening" curl -s http://localhost:8080/healthPass custom environment variables to the command:
repeat --env "API_KEY=secret123" --env "ENV=production" ./deploy.shSet multiple environment variables for testing:
repeat -i 3 --env "DB_HOST=localhost" --env "DB_PORT=5432" ./test-db-connection.shOverride existing environment variables:
repeat --env "PATH=/custom/bin:$PATH" which mycommandKill a command if it takes longer than 2 seconds:
repeat --single-run-timeout-sec 2 sleep 5Stop the entire operation after 30 seconds:
repeat --total-run-timeout-sec 30 ./long-running-test.shCombine both timeouts:
repeat -i 100 --single-run-timeout-sec 5 --total-run-timeout-sec 60 ./api-test.shWait 5 seconds before starting, and wait 1 second between each run:
repeat --initial-delay 5 --in-between-delay 1 echo "Polling..."Wait between 1 and 5 seconds between each run (useful for simulating jitter):
repeat --in-between-delay 1..5 ./simulate-traffic.shRandom initial delay and random in-between delays:
repeat --initial-delay 2..10 --in-between-delay 1..3 ./load-test.shSee detailed output for each run:
repeat -v -i 3 echo "Debug mode"Run a load test 1000 times with random delays:
repeat -i 1000 --in-between-delay 0..2 curl -s http://localhost:8080/api/endpointRun a test until it fails, with a timeout:
repeat --exit-code 1 --total-run-timeout-sec 300 npm testPoll a service every 2 seconds until it's ready:
repeat --match-output "healthy" --in-between-delay 2 curl -s http://localhost:8080/healthTest database connectivity with custom environment variables:
repeat -i 10 \
--env "DB_HOST=localhost" \
--env "DB_PORT=5432" \
--env "DB_NAME=testdb" \
./test-db-connection.shWait for deployment to complete (max 5 minutes):
repeat \
--match-output "Deployment successful" \
--in-between-delay 10 \
--total-run-timeout-sec 300 \
kubectl get deployment my-app -o jsonpath='{.status.conditions[?(@.type=="Available")].status}'Test API with controlled request rate:
repeat -i 100 \
--env "API_TOKEN=your_token" \
--in-between-delay 1 \
--single-run-timeout-sec 5 \
curl -H "Authorization: Bearer \$API_TOKEN" https://api.example.com/endpointRun a comprehensive test with multiple conditions:
repeat \
-i 50 \
--exit-code 0 \
--env "TEST_ENV=staging" \
--env "LOG_LEVEL=debug" \
--initial-delay 5 \
--in-between-delay 2..5 \
--single-run-timeout-sec 10 \
--total-run-timeout-sec 600 \
./integration-test.shTo run the project locally without installing:
cargo run -- [OPTIONS] <COMMAND>Example:
cargo run -- --iterations 3 echo "Running locally"This project contains both unit and integration tests.
To run all tests:
cargo testTo run a specific test:
cargo test test_nameContributions are welcome! If you find a bug or want to add a feature, please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and ensure they are tested.
- Run
cargo fmtto format your code. - Run
cargo testto ensure everything is working. - Submit a Pull Request.