Check data created in default at teardown stage


I’m using k6 for a bit of time now. I’m testing a specific usecase when I create an object and do some other http call (I mimic the behavior of a mobile app in order to test the backend). Then some async stuff is done in the backend side to “finalize” that object. Currently, the test does a “GET” on this object to check it has been finalized “at the right time”, since the mobile app does the same.

Now there is a change in the usecase from mobile side, they will not do the “GET” at the end of the usecase. However, since we already found some issue with the async stuff (for instance, the object is not saved in database, so impossible to “GET” afterward), I still want to check that the object can be retrieved at some point.

I don’t want to add a sleep inside my default function, since the “GET” is not part of the usecase anymore and it will not mimic the mobile app behavior. So I imagine I could somehow collect the id’s of the created objects during the test and try to get them at teardown stage. It will give reasonable time for the async stuff to be done.

I know you cannot pass data from default to teardown stage, and I’m not sure if I would introduce a redis server for this case. My idea would be to write some info in a file and then reopen the file (in the teardown or in another separate test), but I don’t know what would be the acceptable solution here.

Since my usecase is complicated, don’t hesitate to ask for some clarifications.

I’m looking forward to your help.


No help?

Hi @garnet0371!

I would use GitHub - dgzlopes/xk6-kv: A k6 extension to share key-value data between VUs. for this purpose.
Something like this:

import kv from 'k6/x/kv';

const client = new kv.Client('ids', true);

export default function() {
  // do some HTTP requests and get the ID
  const id = doRequest();

  // save the id into KV for later use
  client.set(`id_${id}`, id);

export function teardown() {
  // check ids saved into KV
  const keys = client.viewPrefix('id_');
  for (const key in keys) {
    const id = keys[key];

Hello @bandorko !

I didn’t think about this extension! It seems a bit old but will do the work. The only drawback is that the extension will force an old k6 version to be used. If I want to use it, I will probably fork this extension or make a pull request. I will test it in the following days in an example script to do some experimentation and come back to you, thank you very much!

1 Like


You’re right. I can’t build it with the latest k6, but I found an another kv extension, that I was able to build into the latest k6 GitHub - oleiade/xk6-kv: A key-value store extension for k6. And this one is listed on the page, so sorry for the previous one.

I will test this one instead, hoping that performance throughput of the test will not be badly affected. But as the readme of the project said, redis is the best for this job, but less lightwell.

1 Like