Search code examples
load-testingk6

How to override k6 CLI arguments from within the script?


I have a rather complicated setup which forces me to pass --duration and --vus to k6 CLI.

It ends up looking like

k6 run --vus 200 --duration 60s fixed-scenarios.js

Because of this my custom scenarios are being overridden by a default scenario.

Is there a way to prevent it from within the script?


Solution

  • In k6 order of presence cli flags will override everything else.

    import http from "k6/http";
    
    const options = {
      foo_scenario: {
        executor: "shared-iterations",
        vus: 1,
        iterations: 1,
        maxDuration: "10s",
      },
    };
    
    export default function () {
      http.get("https://stackoverflow.com");
    }
    
    • If you only run with k6 run script.js it will make one request.
    • If you override with cli flags, like k6 run script.js --vus 10 --iterations 10 it'll make 10 ten requests.