grafana / xk6-exec

A k6 extension for running external commands.
Apache License 2.0
20 stars 21 forks source link

failed execution breaks all other tests #17

Open fczuardi opened 10 months ago

fczuardi commented 10 months ago

K6 documentation recommends the use of k6 chaijs for handling errors, using the describe function.

However it does not work with tests that uses exec.command, a failed command execution exits k6 run as well :(

steps to reproduce

// mytest.js
import { describe} from "https://jslib.k6.io/k6chaijs/4.3.4.3/index.js";
import { check } from 'k6'
import exec from 'k6/x/exec';

export function setup (){}
export function teardown (){}
export default function(){

  describe("1", (t) => {
    check(1, {"1 === 1": n => n ===1}) 
  })
  describe("2", (t) => {
    check(1, {"1 === 1": n => n ===1}) 
    let out = exec.command("ls", ["non_existent_file"])
  })
  describe("3", (t) => {
    check(1, {"1 === 1": n => n ===1}) 
  })
}

expected behavior

actual behavior

$ k6 version
k6 v0.45.1 ((devel), go1.20.5, linux/amd64)
Extensions:
  github.com/grafana/xk6-exec v0.3.0, k6/x/exec [js]

$ k6 run mytest.js 

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: mytest.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0015] 2023/10/31 11:48:12 exit status 2 on command: ls non_existent_file 
fczuardi commented 10 months ago

Even with a regular try/catch block this fails:

import { check } from 'k6'
import exec from 'k6/x/exec';

export function setup (){}
export function teardown (){}
export default function(){
  check(1, {"1 === 1": n => n === 1}) 
  check(2, {"2 === 2": n => n === 2}) 
  try {
    let out = exec.command("ls", ["non_existent_file"])
    //should be the same behavior as
    //throw new Error('My error message')
  } catch(e) {
    console.log(e.message)
  }
  check(3, {"3 === 3": n => n === 3}) 
}
fczuardi commented 10 months ago

maybe duplicate or similar than https://github.com/grafana/xk6-exec/issues/12