pythoneventsload-testinglocustteardown

Locust Teardown - Event test stop


I am using events in my locust test: @events.test_stop.add_listener and @events.test_start.add_listener

Problem: @events.test_stop.add_listener does not execute DB request.

Test structure:

Test run parameters:

Example: The same code for @events.test_stop.add_listener and @events.test_start.add_listener

@events.test_start.add_listener
def on_test_start(environment, **kwargs):
    logging.info('Test start. Trying to query the database.')
    response_db = get_count_port_msg()
    logging.info(f'DB response: {response_db}')


@events.test_stop.add_listener
def on_test_stop(environment, **kwargs):
    logging.info('Test stop. Trying to query the database.')
    response_db = get_count_port_msg()
    logging.info(f'DB response: {response_db}')

Response in command line:

[2023-04-26 14:39:06,054] VDI/INFO/locust.main: Starting Locust 2.14.2
[2023-04-26 14:39:17,754] VDI/INFO/root: Test start. Trying to query the database.
[2023-04-26 14:39:17,754] VDI/INFO/root: Execute the request...
[2023-04-26 14:39:17,953] VDI/INFO/root: DB response: 52
[2023-04-26 14:39:17,953] VDI/INFO/locust.runners: Ramping to 1 users at a rate of 1.00 per second
[2023-04-26 14:39:17,953] VDI/INFO/locust.runners: All users spawned: {"LoadTests": 1} (1 total users)
...
[2023-04-26 14:39:23,286] VDI/INFO/root: Iteration limit reached (2), stopping Users at the start of their next task run
[2023-04-26 14:39:23,286] VDI/INFO/root: Last user stopped, quitting runner
[2023-04-26 14:39:23,286] VDI/INFO/root: Test stop. Trying to query the database.
[2023-04-26 14:39:23,286] VDI/INFO/root: Execute the request...

Press CTRL+C to exit and view the report.

Question: Why don't I have the same on_test_stop response as on_test_start? Thanks.


Solution

  • I made a fix/workaround and released it in locust-plugins 3.3.0.