Events

You can register one or several functions to receive events emited during the load test. You just need to decorate the function with the molotov.events() fixture described below:

molotov.events()

Called everytime Molotov sends an event

Arguments received by the decorated function:

  • event Name of the event
  • extra argument(s) specific to the event

The decorated function should be a coroutine.

IMPORTANT This function will directly impact the load test performances

Current supported events and their keyword arguments:

  • sending_request: session, request
  • response_received: session, response, request
  • current_workers: workers
  • scenario_start: scenario, wid
  • scenario_success: scenario, wid
  • scenario_failure: scenario, exception, wid

The framework will gradually get more events triggered from every step in the load test cycle.

In the example below, all events are printed out:

"""

This Molotov script demonstrates how to hook events.

"""

import molotov


@molotov.events()
async def print_request(event, **info):
    if event == "sending_request":
        print("=>")


@molotov.events()
async def print_response(event, **info):
    if event == "response_received":
        print("<=")


@molotov.scenario(100)
async def scenario_one(session):
    async with session.get("http://localhost:8080") as resp:
        res = await resp.json()
        assert res["result"] == "OK"
        assert resp.status == 200