Brainstorming/Tips: How to run specific groups, requests and/or specific check from a single file with thousands of lines

Hello,

Let’s say we ran these commands and the .js file is created from a really huge api. That means it ended being a really huge file.

In addition to this context, we are also refactoring our API which means we will be converting our api with some high frequency.
From my understanding, every time we convert we can either overwrite our existing file and losing all our custom k6 lines in the process. Or, create a new file and lose our custom k6 lines added as well.

So we are thinking on some of organization that could allow us to convert our api with frequency but without losing our custom k6 added lines as much as we can.

This thinking led me to think about tags, and I found k6 tags and groups documentation -----> https://k6.io/docs/using-k6/tags-and-groups
We would still need to add tags to each request manually but cost / benefit, it seems to be minimal effort if we compare it with re-write everything again.

Does anyone has a project sample with these tests (tags & groups) we can take a look at?

Any other suggestion on the table?

Thank you very much,

Regards

Hi,
Just the read the documentation , tags seems to be for later results filtering only.

How can we run a specific request or group from a very large file with several groups and requests in it?

Thank you

Hi there,

so this question is similar to this: How to run only certain groups of requests

While there’s currently no way to run specific groups, which sounds like a good feature to have in k6, you can hack your way around it to use the same workaround recommended in that thread and issue for your OpenAPI generated script.

It’s not pretty, but here’s a potential workflow you could automate to transform the generated script:

# Replace all group() calls with a call to a custom mgroup() instead
sed -i 's:group(:mgroup(:g' script.js
# Append a global regex and the mgroup() function to test an environment variable for it
cat <<'EOF' >> script.js
const re = new RegExp(__ENV.K6_GROUPS ? __ENV.K6_GROUPS : '.*');
function mgroup(name, fn) {
  if (re.test(name)) {
    return group(name, fn);
  }
}
EOF

Then running the script by default will execute all groups, but you can select which ones to execute with the K6_GROUPS env var, e.g.:
K6_GROUPS='post|get' k6 run script.js.

This is far from ideal of course, but hope it helps until this is supported natively in k6. Or maybe someone else has a better suggestion :slight_smile:

1 Like

Hi imirc,

Nice! That looks pretty interesting, thank you !