VUS Scaling via REST API "Pause Error"

I am following a UI guide in the k6 blogs with a test scenario with externally-controlled executor. Pause and resume works perfectly fine via both k6 commands (k6 pause, k6 resume).

For scaling, k6 scale seems to work perfectly fine, however, when I followed the guide to increase or decrease VUs via the REST API patch endpoint, I get Pause Error.

When I tried to increase VUs when it is running, I get an error saying that “test execution wasn’t paused”. However, when I try to increase the VUs when it is paused, I get an error saying that “test execution was already paused”.

Does k6 scale increase or decrease VUs differently than sending a PATCH request to the k6 endpoint? I would assume that these internal control commands would still interact with the k6 endpoints like how it was suggested in the k6 REST API guide. How should I look into it to make increase and decrease work?

Hi @Lami :wave:

First and foremost, welcome to the forum :tada:

Really sorry to get back to you so late :bowing_man:

Unfortunately, I ran a few tests and experimentations, and I can’t seem to reproduce the issue that you’re reporting. Furthermore, as far as I can tell, the k6 scale command does use the REST API too.
Both the PATCH endpoint, and the scale command seem to behave as expected in my case. Thus, could you post some examples of the commands you run, and the output you get vs the output you expect? :slight_smile:

For reference, here’s my testing material:

I run this script:

import http from "k6/http";

export const options = {
  discardResponseBodies: true,
  scenarios: {
    contacts: {
      executor: "externally-controlled",
      vus: 10,
      maxVUs: 50,
      duration: "10m",
    },
  },
};

export default function () {
  http.get("https://test.k6.io/contacts.php");
}

If I call the PATCH endpoint to pause, it behaves as expected, and k6 pauses:

curl -X PATCH -d "{\"data\": {\"attributes\": {\"paused\": false}}}" http://localhost:6565/v1/status | jq
{
  "data": {
    "type": "status",
    "id": "default",
    "attributes": {
      "status": 7,
      "paused": false,
      "vus": 10,
      "vus-max": 50,
      "stopped": false,
      "running": true,
      "tainted": false
    }
  }
}

Changing the VUs count on the fly also works as expected (I also observe it in k6’s running output):

curl -X PATCH -d "{\"data\": {\"attributes\": {\"vus\": 40}}}" http://localhost:6565/v1/status | jq
{
  "data": {
    "type": "status",
    "id": "default",
    "attributes": {
      "status": 7,
      "paused": false,
      "vus": 40,
      "vus-max": 50,
      "stopped": false,
      "running": true,
      "tainted": false
    }
  }
}

Cheers