I am running a load test with k6, which tests my service with 6 scenarios. I am running my service with docker-compose and I want to restart my service between each scenario. I couldn't find a built-in method for this so I added a function to restart the service and added some code to call that function at the start of each scenario ( I declared a counter for each scenario with initial value 0 and call the restart function only when the counter is 1). but the function is getting called per VU, not as I expected. Is there any solution for this?
Thanks in advance
It sounds like you are not executing the scenarios in parallel (as I would expect from k6 scenarios), but rather in sequence.
There isn't anything builtin in k6, but why not have a simple shell script which performs the following steps in order:
k6 run scn1.js;
./restart-services.sh;
k6 run scn2.js;
./restart-services.sh;
k6 run scn3.js;
./restart-services.sh;
k6 run scn4.js;
Or wrap it in a loop:
for scn in 1 2 3 4; do
./restart-services.sh;
k6 run "scn${scn}.js";
done