Overview
HTTPSpec supports configuration through environment variables to control test execution behavior. Currently, HTTPSpec provides one environment variable for customizing parallel execution.Available Variables
HTTP_THREAD_COUNT
Controls the number of concurrent threads used for parallel test execution. Type: Integer (unsigned) Default:1
Valid Range: 1 to system-dependent maximum
Source: main.zig:26
The default value of
1 means tests run sequentially. Increase this value to run multiple test files in parallel.Description
HTTPSpec uses a thread pool to execute test files concurrently. Each test file is processed by a single thread, and theHTTP_THREAD_COUNT variable determines how many test files can run simultaneously.
How it works:
- HTTPSpec discovers all
.httpand.httpspecfiles to run - A thread pool is initialized with
HTTP_THREAD_COUNTworker threads (main.zig:57-61) - Each test file is dispatched to an available thread
- Tests within a single file always run sequentially
- The main thread waits for all tests to complete before reporting results
Usage Examples
Run tests sequentially (default):Performance Considerations
Choosing the Right Thread Count
Choosing the Right Thread Count
Factors to consider:
- Number of test files: More threads than test files provides no benefit
- CPU cores: Setting threads higher than CPU core count may not improve performance
- I/O vs CPU bound: HTTP tests are typically I/O bound (waiting for network), so you can use more threads than CPU cores
- Server capacity: Too many parallel requests may overwhelm the test server
- Rate limits: Some APIs have rate limits that parallel execution might trigger
- Small test suite (1-10 files):
4-8threads - Medium test suite (10-50 files):
8-16threads - Large test suite (50+ files):
16-32threads - Local development: Number of CPU cores or less
- CI/CD pipelines:
4-8threads (to avoid overwhelming shared resources)
Thread Safety
The test reporter uses mutex locks to safely update test statistics from multiple threads (test_reporter.zig:8, 35-53):Error Handling
Invalid Values: IfHTTP_THREAD_COUNT contains an invalid integer value, HTTPSpec falls back to the default of 1:
std.process.parseEnvVarInt() which catches all parsing errors and returns the default value.
System Limits:
The actual thread count may be limited by:
- Operating system thread limits
- Available memory
- File descriptor limits (each HTTP connection uses a file descriptor)
Memory Management
Arena Allocators Per Test
Each test file execution uses an isolated arena allocator (main.zig:114-116):- Memory isolation between test files
- Automatic cleanup after each test
- No memory leaks from individual tests
- Simplified memory management
- Each thread manages its own arena
- Memory usage scales with thread count
- Peak memory = (average test memory) × (thread count)
The main program uses a
DebugAllocator to detect memory leaks during development (main.zig:11-13).Configuration Examples
Development Environment
CI/CD Pipeline
GitHub Actions:Docker
Dockerfile:Future Configuration Options
The following environment variables are not currently implemented but may be added in future versions:
Potential Future Variables
HTTP_TIMEOUT: Request timeout in secondsHTTP_RETRY_COUNT: Number of retries for failed requestsHTTP_VERBOSE: Enable verbose loggingHTTP_FOLLOW_REDIRECTS: Enable/disable redirect followingHTTP_MAX_REDIRECTS: Maximum number of redirects to followHTTP_CONNECT_TIMEOUT: Connection timeout in secondsHTTP_USER_AGENT: Custom User-Agent header
Best Practices
1. Set Appropriate Thread Count
2. Document Team Standards
Include a.envrc or .env.example file in your project:
3. CI/CD Optimization
4. Load Testing Considerations
5. Local vs CI Configuration
Debugging
Check Current Configuration
Verify Thread Usage
HTTPSpec doesn’t currently log the thread count, but you can verify behavior:Unset Variable
See Also
- Troubleshooting - Debug test execution issues
- Quick Start - Getting started guide
- Installation - Build and install HTTPSpec