Index
provide.testkit.chaos
¶
Chaos testing utilities for property-based testing with Hypothesis.
This module provides reusable Hypothesis strategies and fixtures for chaos engineering in tests. It enables systematic exploration of edge cases, race conditions, and failure scenarios that are difficult to test with traditional methods.
Key Features
- Property-based testing strategies for common chaos patterns
- Time manipulation and clock skew simulation
- Concurrency and race condition triggers
- I/O failure injection patterns
- Reusable pytest fixtures for chaos testing
Example
Functions¶
async_event_patterns
¶
Generate async event patterns for coroutine testing.
Creates patterns of async events, delays, and scheduling scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_events
|
int
|
Maximum number of events to generate |
50
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of event dictionaries |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
buffer_overflow_patterns
¶
Generate buffer overflow scenarios.
Creates situations where data exceeds buffer capacity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_buffer_size
|
int
|
Maximum buffer size in bytes |
1024 * 1024
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing buffer overflow configuration |
Example
Source code in provide/testkit/chaos/io_strategies.py
chaos_timings
¶
chaos_timings(
draw: DrawFn,
min_value: float = 0.001,
max_value: float = 10.0,
allow_zero: bool = False,
) -> float
Generate chaotic timing values for unpredictable delays.
Useful for testing timeout handling, race conditions, and time-sensitive code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_value
|
float
|
Minimum timing value in seconds |
0.001
|
max_value
|
float
|
Maximum timing value in seconds |
10.0
|
allow_zero
|
bool
|
Whether to allow zero delay |
False
|
Returns:
| Type | Description |
|---|---|
float
|
A floating-point timing value in seconds |
Source code in provide/testkit/chaos/strategies.py
clock_skew
¶
Generate clock skew scenarios for distributed system testing.
Simulates clock drift, NTP sync issues, and timezone problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_skew
|
float
|
Maximum clock skew in seconds |
300.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing skew configuration |
Example
Source code in provide/testkit/chaos/time_strategies.py
deadline_scenarios
¶
deadline_scenarios(
draw: DrawFn,
min_deadline: float = 0.1,
max_deadline: float = 10.0,
) -> dict[str, Any]
Generate deadline-based test scenarios.
Creates scenarios with operations that may or may not meet their deadlines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_deadline
|
float
|
Minimum deadline in seconds |
0.1
|
max_deadline
|
float
|
Maximum deadline in seconds |
10.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing deadline scenario configuration |
Example
Source code in provide/testkit/chaos/time_strategies.py
deadlock_scenarios
¶
Generate resource lock patterns that may cause deadlocks.
Creates scenarios where circular dependencies between locks might occur.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
num_resources
|
int
|
Number of lockable resources |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing deadlock scenario configuration |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
disk_full_scenarios
¶
Generate disk space exhaustion scenarios.
Simulates running out of disk space during operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing disk full scenario |
Example
Source code in provide/testkit/chaos/io_strategies.py
edge_values
¶
Generate boundary and edge-case values for a given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
value_type
|
type
|
Type to generate edge values for |
int
|
Returns:
| Type | Description |
|---|---|
Any
|
Edge-case value of the specified type |
Example
Source code in provide/testkit/chaos/strategies.py
failure_patterns
¶
failure_patterns(
draw: DrawFn,
max_failures: int = 10,
exception_types: (
tuple[type[Exception], ...] | None
) = None,
) -> list[tuple[int, type[Exception]]]
Generate patterns of when and how failures should occur.
Returns a list of (iteration_number, exception_type) tuples for failure injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_failures
|
int
|
Maximum number of failures to generate |
10
|
exception_types
|
tuple[type[Exception], ...] | None
|
Specific exception types to use (defaults to common types) |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, type[Exception]]]
|
List of (when_to_fail, exception_class) tuples |
Example
Source code in provide/testkit/chaos/strategies.py
file_corruption_patterns
¶
Generate file corruption scenarios.
Simulates various types of file corruption for testing recovery.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing corruption configuration |
Example
Source code in provide/testkit/chaos/io_strategies.py
file_sizes
¶
file_sizes(
draw: DrawFn,
min_size: int = 0,
max_size: int = 10 * 1024 * 1024,
include_huge: bool = False,
) -> int
Generate realistic file size distributions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_size
|
int
|
Minimum file size in bytes |
0
|
max_size
|
int
|
Maximum file size in bytes |
10 * 1024 * 1024
|
include_huge
|
bool
|
Include very large file sizes (GB range) |
False
|
Returns:
| Type | Description |
|---|---|
int
|
File size in bytes |
Example
Source code in provide/testkit/chaos/io_strategies.py
jitter_patterns
¶
jitter_patterns(
draw: DrawFn,
base_interval: float = 1.0,
max_jitter_percent: float = 50.0,
) -> list[float]
Generate network-like timing jitter patterns.
Simulates variable latency and timing uncertainty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
base_interval
|
float
|
Base time interval in seconds |
1.0
|
max_jitter_percent
|
float
|
Maximum jitter as percentage of base interval |
50.0
|
Returns:
| Type | Description |
|---|---|
list[float]
|
List of intervals with jitter applied |
Example
Source code in provide/testkit/chaos/time_strategies.py
lock_contention_patterns
¶
lock_contention_patterns(
draw: DrawFn,
num_locks: int = 5,
num_operations: int = 20,
) -> dict[str, Any]
Generate lock contention patterns for testing synchronization.
Creates scenarios with varying levels of lock contention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
num_locks
|
int
|
Number of available locks |
5
|
num_operations
|
int
|
Number of operations competing for locks |
20
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing lock contention configuration |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
lock_file_scenarios
¶
Generate file lock conflict scenarios.
Creates situations with competing file locks and stale locks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing lock scenario configuration |
Example
Source code in provide/testkit/chaos/io_strategies.py
malformed_inputs
¶
malformed_inputs(
draw: DrawFn,
include_huge: bool = True,
include_empty: bool = True,
include_special: bool = True,
) -> Any
Generate edge-case inputs for robust testing.
Creates various malformed, extreme, or unusual inputs that often expose bugs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
include_huge
|
bool
|
Include very large strings/data |
True
|
include_empty
|
bool
|
Include empty/None values |
True
|
include_special
|
bool
|
Include special numeric values (NaN, inf) |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
Various malformed input values |
Example
Source code in provide/testkit/chaos/strategies.py
network_error_patterns
¶
Generate network failure patterns.
Creates sequences of network errors and recovery scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of network error events |
Example
Source code in provide/testkit/chaos/io_strategies.py
path_traversal_patterns
¶
Generate path traversal attack patterns.
Creates potentially malicious path patterns for security testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
str
|
A path string that might contain traversal attempts |
Example
Source code in provide/testkit/chaos/io_strategies.py
permission_patterns
¶
Generate file permission scenarios.
Creates various permission configurations for testing access control.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing permission configuration |
Example
Source code in provide/testkit/chaos/io_strategies.py
pid_recycling_scenarios
¶
Generate PID recycling attack scenarios.
Creates scenarios where PIDs might be reused, testing protection mechanisms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing PID recycling scenario |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
process_pool_patterns
¶
process_pool_patterns(
draw: DrawFn,
max_workers: int = 10,
max_tasks: int = 100,
) -> dict[str, Any]
Generate process pool execution patterns.
Creates scenarios for testing process pool behavior under various conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_workers
|
int
|
Maximum number of worker processes |
10
|
max_tasks
|
int
|
Maximum number of tasks to submit |
100
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing pool configuration |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
race_condition_triggers
¶
race_condition_triggers(
draw: DrawFn,
num_operations: int = 10,
max_delay: float = 0.1,
) -> list[tuple[int, float]]
Generate timing patterns designed to trigger race conditions.
Returns operation timings that maximize the chance of exposing race conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
num_operations
|
int
|
Number of concurrent operations |
10
|
max_delay
|
float
|
Maximum delay between operations in seconds |
0.1
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, float]]
|
List of (operation_id, delay_before_execution) tuples |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
rate_burst_patterns
¶
rate_burst_patterns(
draw: DrawFn,
max_burst_size: int = 1000,
max_duration: float = 10.0,
) -> list[tuple[float, int]]
Generate traffic burst patterns for rate limiting tests.
Returns a list of (timestamp, request_count) representing burst patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_burst_size
|
int
|
Maximum number of requests in a burst |
1000
|
max_duration
|
float
|
Maximum duration of burst pattern in seconds |
10.0
|
Returns:
| Type | Description |
|---|---|
list[tuple[float, int]]
|
List of (time_offset, request_count) tuples |
Example
Source code in provide/testkit/chaos/time_strategies.py
resource_limits
¶
resource_limits(
draw: DrawFn,
min_memory: int = 1024,
max_memory: int = 1024 * 1024 * 100,
min_timeout: float = 0.01,
max_timeout: float = 60.0,
) -> dict[str, Any]
Generate resource constraint scenarios.
Creates various resource limit configurations for testing behavior under constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_memory
|
int
|
Minimum memory limit in bytes |
1024
|
max_memory
|
int
|
Maximum memory limit in bytes |
1024 * 1024 * 100
|
min_timeout
|
float
|
Minimum timeout in seconds |
0.01
|
max_timeout
|
float
|
Maximum timeout in seconds |
60.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with resource limit configuration |
Example
Source code in provide/testkit/chaos/strategies.py
retry_backoff_patterns
¶
Generate retry and backoff patterns for resilience testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_retries
|
int
|
Maximum number of retries |
10
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing retry configuration |
Example
Source code in provide/testkit/chaos/time_strategies.py
task_cancellation_patterns
¶
Generate task cancellation scenarios for async testing.
Creates patterns of task creation and cancellation to test cleanup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
num_tasks
|
int
|
Number of tasks in the pattern |
20
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of task configuration dictionaries |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
thread_counts
¶
thread_counts(
draw: DrawFn,
min_threads: int = 1,
max_threads: int = 100,
include_extremes: bool = True,
) -> int
Generate thread count scenarios for concurrency testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_threads
|
int
|
Minimum number of threads |
1
|
max_threads
|
int
|
Maximum number of threads |
100
|
include_extremes
|
bool
|
Include edge cases (1 thread, max threads) |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of threads to spawn |
Example
Source code in provide/testkit/chaos/concurrency_strategies.py
time_advances
¶
time_advances(
draw: DrawFn,
min_advance: float = 0.0,
max_advance: float = 3600.0,
allow_backwards: bool = False,
) -> float
Generate time progression patterns for time manipulation testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_advance
|
float
|
Minimum time advance in seconds |
0.0
|
max_advance
|
float
|
Maximum time advance in seconds |
3600.0
|
allow_backwards
|
bool
|
Allow negative time advances (backwards jumps) |
False
|
Returns:
| Type | Description |
|---|---|
float
|
Time advance value in seconds (can be negative if allowed) |
Example
Source code in provide/testkit/chaos/time_strategies.py
timeout_patterns
¶
timeout_patterns(
draw: DrawFn,
min_timeout: float = 0.01,
max_timeout: float = 60.0,
include_none: bool = True,
) -> float | None
Generate realistic timeout scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_timeout
|
float
|
Minimum timeout value in seconds |
0.01
|
max_timeout
|
float
|
Maximum timeout value in seconds |
60.0
|
include_none
|
bool
|
Whether to include None (no timeout) as a possibility |
True
|
Returns:
| Type | Description |
|---|---|
float | None
|
Timeout value in seconds, or None |
Example
Source code in provide/testkit/chaos/time_strategies.py
unicode_chaos
¶
unicode_chaos(
draw: DrawFn,
include_emoji: bool = True,
include_rtl: bool = True,
include_zero_width: bool = True,
include_surrogates: bool = False,
) -> str
Generate problematic Unicode strings for testing.
Creates strings with emoji, RTL text, zero-width characters, and other Unicode edge cases that often cause issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
include_emoji
|
bool
|
Include emoji characters |
True
|
include_rtl
|
bool
|
Include right-to-left text |
True
|
include_zero_width
|
bool
|
Include zero-width characters |
True
|
include_surrogates
|
bool
|
Include surrogate pairs (can be problematic) |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A Unicode string with chaotic properties |