Running scenarios, context cancel, request not sent

just running scenarios on an aws server with 3 test cases, get the following error:
level=error msg=“context canceled”
Request:
sometimes, there could be additional error as “iteration interrupted”.
I believe I have set long enough duration, and the application under test doesn’t throw time out errors. It seems to me that the k6 stops the execution before the time out window is exceeded.
The gracefulStop window is 3 mins per test case, but the script stops after 1.5 min.

scenarios: (100.00%) 3 executors, 3 max VUs, 13m15s max duration (incl. graceful stop):
           * TC_1: 1 iterations shared among 1 VUs (maxDuration: 10m0s, exec: da_TC_1, startTime: 1s, gracefulStop: 3m0s)
           * TC_2: 1 iterations shared among 1 VUs (maxDuration: 10m0s, exec: da_TC_2, startTime: 5s, gracefulStop: 3m0s)
           * TC_3: 1 iterations shared among 1 VUs (maxDuration: 10m0s, exec: da_TC_3, startTime: 10s, gracefulStop: 3m0s)

Here is my script:

let failedRequestCounter = new Counter('failedRequestCounter');
 
export let options = {
      thresholds: {
        failedRequestCounter: [{ threshold: 'count===0', abortOnFail: true}],
    },
    scenarios: {
        TC_1: {
            executor: 'shared-iterations',
            exec: 'DA_TC_1',
            vus: 1,
            iterations: 1,
            gracefulStop: '3m',
            startTime: '0s',
        },

        TC_2: {
            executor: 'shared-iterations',
            exec: 'da_TC_2',
            vus: 1,
            iterations: 1,
            startTime: '5s',
            gracefulStop: '3m'
        },
        /*
       TC_3: {
            executor: 'shared-iterations',
            exec: 'da_TC_3',
            iterations: 1,
            startTime: '10s',
            gracefulStop: '3m'
        },
        */
export function da_TC_1 ()
{
    group("TC_1", function () {
        TC_1();
    });
}
export function da_TC_2 ()
{
    group("TC_1", function () {
        TC_2();
    });
}
export function da_TC_3 ()
{
    group("TC_1", function () {
        TC_3();
    });
}

Here are my questions:

  1. Why don’t gracefulStop and maxduration time window matter and k6 stops prematurely?
  2. how to catch the context cancel error?
    Thanks
    Min

Hi @minwu,

  1. gracefulStop is on top of maxDuration which is 10 minutes by default and it is being taken into account. Also is timeout, I did test it with the following golang server and k6 script and there was no problem with a 5 minute long request.
package main

import (
	"fmt"
	"html"
	"log"
	"net/http"
	"time"
)

func main() {
	http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("something")
		time.Sleep(time.Minute * 5)
		fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
		fmt.Println("Done")
	})

	log.Fatal(http.ListenAndServe(":8080", nil))
}
import http from "k6/http";
export default function() {
    var res = http.get("http://localhost:8080/bar", {"timeout": "3000000"})
    console.log(JSON.stringify(res, null, "  "));
}

Which did finish but it reminded me that timeout for http requests is actually in milliseconds and if you write “20s” it will decided it is 20 milliseconds :man_facepalming: so maybe you also have not configured that correctly?
2. It is also really quite possible is that the threshold was breached and that stopped your test. This should be easily noticable in the end result.

Please if you have more problems do include the output logs and the end results so there is more information to go on.
Hope this helps

1 Like

mstoykov,
Thanks for your information.
Indeed, the threshold was breached and the test was stopped because the abortOnFail: true. I reset abortOnFail to be false, and execution continues to next test case and my cleanup process is executed as expected.
Regards,
Min