Simple Python 3.5+ tool to write load tests.
To create a load test, you need to create a Python module with some functions decorated with the scenario decorator – those functions needs to be coroutines. When executed, the function receives a session object inherited from aiohttp.ClientSession.
Here’s a full example :
from molotov import scenario _API = 'http://localhost:8080' @scenario(40) async def scenario_one(session): async with session.get(_API) as resp: res = await resp.json() assert res['result'] == 'OK' assert resp.status == 200 @scenario(60) async def scenario_two(session): async with session.get(_API) as resp: assert resp.status == 200
When molotov runs, it creates some workers (coroutines) that will run the functions indefinitely until the test is over. A test is over when the time in seconds provided by -d option is reached.
Each worker randomly picks one scenario to execute, given their weights. Once it’s finished, it picks the next one, and so on. In our example, scenario_two is picked ~60% of the time.
Check out aiohttp’s documentation to understand how to work with a session object.
To run the load script, you can provide its module name or its path. In the example below, the script is executed in quiet mode with 10 processes and 200 workers for 60 seconds. It stops on the first failure:
$ molotov molotov/tests/example.py -p 10 -w 200 -d 60 -qx