Scenario
This page contains the API documentation for the gradual.runners.scenario module.
gradual.runners.scenario
The scenario module provides the Scenario class which manages the execution of test requests within a scenario. It handles concurrency, ramp-up, and different types of requests (HTTP, WebSocket).
Classes
Scenario(scenario_config: ScenarioConfig)
Manages the execution of test requests within a scenario.
The Scenario class is responsible for: 1. Managing concurrent execution of test requests 2. Handling ramp-up of concurrent requests 3. Supporting different types of requests (HTTP, WebSocket) 4. Managing test sessions and iterators 5. Providing graceful shutdown capabilities
Attributes:
| Name | Type | Description |
|---|---|---|
scenario_config |
ScenarioConfig
|
Configuration for this test scenario |
running_request_tasks |
list[Greenlet]
|
List of currently running request tasks |
last_request_idx |
int
|
Index of the last request type used |
stop_scenario_execution |
bool
|
Flag to control scenario execution |
requests |
list[_Request]
|
List of request instances |
iterator |
RequestIterator
|
Iterator for cycling through request types |
Initialize a new test scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario_config
|
ScenarioConfig
|
Configuration for this test scenario |
required |
Source code in src/gradual/runners/scenario.py
Attributes
scenario_config = scenario_config
instance-attribute
running_request_tasks: list[gevent.Greenlet] = []
instance-attribute
last_request_idx: int = 0
instance-attribute
stop_scenario_execution = False
instance-attribute
requests: list[_Request] = []
instance-attribute
iterator = None
instance-attribute
Functions
do_ramp_up(ramp_up_value)
Increase the number of concurrent requests up to the specified value.
This method: 1. Creates new request instances based on the request type 2. Manages HTTP sessions for HTTP requests 3. Spawns new gevent tasks for each request 4. Tracks running requests and their tasks
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ramp_up_value
|
int
|
Target number of concurrent requests to achieve |
required |
Source code in src/gradual/runners/scenario.py
execute()
Execute the test scenario with configured ramp-up behavior.
This method: 1. Starts with minimum concurrency 2. Gradually increases concurrency based on ramp-up configuration 3. Handles both run-once and continuous execution modes 4. Manages wait times between ramp-ups 5. Provides detailed logging of execution progress
Source code in src/gradual/runners/scenario.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
stop_scenario()
Stop the scenario execution gracefully.
This method: 1. Sets the stop flag for the scenario 2. Signals all running requests to stop 3. Ensures clean shutdown of all test activities