You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AsyncFuzzExecutor is a core component that bridges the strategy components (test case generators) and the fuzzing engine. It provides a robust asynchronous execution framework with concurrency control, error handling, and retry mechanisms.
3
+
The AsyncFuzzExecutor is a core component that bridges the strategy components (test case generators) and the fuzzing engine. It provides a robust asynchronous execution framework with semaphore-based concurrency controland error handling.
4
4
5
5
## Architecture
6
6
@@ -12,75 +12,101 @@ graph TD
12
12
B -->|Execute with Concurrency Control| C[Fuzzing Engine]
13
13
C -->|Results| D[Result Collection]
14
14
B -->|Error Handling| E[Error Processing]
15
-
B -->|Retry Logic| F[Retry Mechanism]
15
+
B -->|Thread Pool| F[Sync Operations]
16
16
```
17
17
18
18
## Features
19
19
20
-
-**Concurrency Control**: Limits the number of concurrent operations to prevent resource exhaustion
21
-
-**Timeout Handling**: Enforces timeouts on operations to prevent hanging
22
-
-**Error Handling**: Captures and processes exceptions from operations
23
-
-**Retry Mechanism**: Automatically retries failed operations with exponential backoff
20
+
-**Concurrency Control**: Uses semaphore to limit the number of concurrent operations
21
+
-**Error Handling**: Captures and collects exceptions from operations automatically
24
22
-**Batch Execution**: Executes multiple operations concurrently with result aggregation
25
-
-**Resource Management**: Proper cleanup of resources during shutdown
23
+
-**Mixed Execution**: Handles both async and sync operations via thread pool
24
+
-**Hypothesis Integration**: Wraps Hypothesis strategies to prevent asyncio deadlocks
25
+
-**Resource Management**: Proper cleanup of thread pool resources during shutdown
26
26
27
27
## Usage
28
28
29
-
### Basic Execution
29
+
### Batch Execution
30
30
31
31
```python
32
32
from mcp_fuzzer.fuzz_engine.executor import AsyncFuzzExecutor
33
33
34
34
# Create an executor with max concurrency of 5
35
35
executor = AsyncFuzzExecutor(max_concurrency=5)
36
36
37
-
# Execute an async operation
38
-
asyncdefmy_operation(value):
39
-
# Some async operation
40
-
return value *2
41
-
42
-
result =await executor.execute(my_operation, 10)
37
+
try:
38
+
# Define an async operation
39
+
asyncdefmy_operation(value):
40
+
# Some async operation
41
+
return value *2
42
+
43
+
# Prepare operations as (function, args, kwargs) tuples
44
+
operations = [
45
+
(my_operation, [5], {}),
46
+
(my_operation, [10], {}),
47
+
(my_operation, [15], {})
48
+
]
49
+
50
+
# Execute all operations concurrently
51
+
results =await executor.execute_batch(operations)
52
+
53
+
# Process successful results
54
+
for result in results["results"]:
55
+
print(f"Success: {result}")
56
+
57
+
# Process errors
58
+
for error in results["errors"]:
59
+
print(f"Error: {error}")
60
+
61
+
finally:
62
+
# Shutdown the executor and clean up resources
63
+
await executor.shutdown()
43
64
```
44
65
45
-
### Retry Mechanism
66
+
### Error Handling
46
67
47
68
```python
48
-
# Execute with retry
49
-
result =await executor.execute_with_retry(
50
-
my_operation,
51
-
10,
52
-
retry_count=3,
53
-
retry_delay=1.0
54
-
)
69
+
asyncdefoperation_with_errors(value):
70
+
if value %2==0:
71
+
raiseValueError(f"Even value not allowed: {value}")
72
+
return value *2
73
+
74
+
# Errors are automatically collected
75
+
operations = [(operation_with_errors, [i], {}) for i inrange(10)]
76
+
results =await executor.execute_batch(operations)
77
+
78
+
print(f"Successful: {len(results['results'])}")
79
+
print(f"Failed: {len(results['errors'])}")
55
80
```
56
81
57
-
### Batch Execution
82
+
### Mixed Async and Sync Operations
58
83
59
84
```python
60
-
# Define multiple operations
85
+
# Async operation
86
+
asyncdefasync_op():
87
+
await asyncio.sleep(0.1)
88
+
return"async"
89
+
90
+
# Sync operation (runs in thread pool)
91
+
defsync_op():
92
+
returnsum(range(1000))
93
+
61
94
operations = [
62
-
(my_operation, [5], {}),
63
-
(my_operation, [10], {}),
64
-
(my_operation, [15], {})
95
+
(async_op, [], {}),
96
+
(sync_op, [], {})
65
97
]
66
98
67
-
# Execute all operations concurrently
68
99
results =await executor.execute_batch(operations)
69
-
70
-
# Process successful results
71
-
for result in results["results"]:
72
-
print(f"Success: {result}")
73
-
74
-
# Process errors
75
-
for error in results["errors"]:
76
-
print(f"Error: {error}")
77
100
```
78
101
79
-
### Cleanup
102
+
### Hypothesis Strategy Integration
80
103
81
104
```python
82
-
# Shutdown the executor and clean up resources
83
-
await executor.shutdown()
105
+
from hypothesis import strategies as st
106
+
107
+
# Run Hypothesis strategy without asyncio deadlocks
0 commit comments