grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
25.55k stars 1.26k forks source link

Scenario's don't respect Lifecycle functions #3784

Open ahmednkhan24 opened 4 months ago

ahmednkhan24 commented 4 months ago

Brief summary

I have a K6 project with multiple test files. I'm able to incorporate all of these tests using K6 Scenarios.

I now want to include K6 Lifecycle functions, like setup and teardown for each test.

However, there's no way to specify a setup function in a scenario, similar to how the exec value specifies what function is invoked for the scenario.

If any one test file exports a setup function, that same setup function is used for all tests.

k6 version

v0.50.0

OS

Windows 11

Docker version and image (if applicable)

No response

Steps to reproduce the problem

options.ts

import { Options } from 'k6/options';

const scenarios: Options["scenarios"] = {
  scenario1: {
     exec: 'scenario1FunctionHandler',
     ...
  },
  scenario2: {
     exec: 'scenario2FunctionHandler',
     ...
  }
};

export const options: Options = { scenarios };

test1.ts

export function setup() {
  console.log('test1 setup function');
}

export function scenario1FunctionHandler() {
  ...
}

test2.ts

export function setup() {
  console.log('test2 setup function');
}

export function scenario2FunctionHandler() {
  ...
}

Expected behaviour

The setup for each test respects what it exports.

Actual behaviour

Only 1 setup function is used for all tests

oleiade commented 3 months ago

Hi @ahmednkhan24 πŸ‘‹πŸ»

Thanks a lot for submitting this feature request πŸ™‡πŸ»

We are aware of this and have it on our radar already. However, it is still being determined whether we will make this possible in the future. We'll make sure to let you know as soon as there is progress on that front πŸ™‚

bdshadow commented 2 months ago

hello, is there any estimation about this bug?