Store/Write data from setup and read in default/main function

I want to load test transactions API but for this I have to first create let’s say 3 Million accounts by invoking a Rest API and somehow store the accountId’s it gives back in response (do this in setup?).

Question is where do I write accountIds from create account API and use those in load test (for Transactions API)?

sharedarrays might work…

not sure how it would respond to 3 million elements though.

Other options would be some sort of in memory datastore, such as redis

1 Like

Well I just tried this option and looks like you can’t make a http call in init context (need to call Create Account API) ? So how can I load data into SharedArray?

What’s the preferred way to have test data, if I can’t do this in either setup or init?

Reference: How to use data from an json endpoint with SharedArray?

No idea how’s others have done it but I’m a big fan of redis or jmeter’s simple table server for intra virtual user data stores but never had to have 3 million elements!

you’d need to be comfortable with extensions and ability to setup a redis server. I am on both counts.

import http from 'k6/http';
import redis from 'k6/x/redis';

// setup the redis client
const client = redis.newClient("performance-testing-redis.cache.amazonaws.com:6379");

export function setup() {

  // clear the redis data stores.
  console.log("clearing Meetings");
  redis.do(client,"del","Meetings");
  // make a http call to get the details, hard coding for example
var venueMnemonic = "RAN";
var raceType = "G";
var raceNumber = "1";
// write details to redis as a json
 const Details = JSON.stringify({
        "venueMnemonic": venueMnemonic,
        "raceType": raceType,
        "raceNumber": raceNumber,
      });
  redis.do(client,"sadd","Meetings",Details);
  console.log("loading Meetings complete");
  return;
}

export default function () {
    //
    // get randome details from redis.
    //
    var DetailData = redis.do(client,"srandmember","Meetings");
    var DetailJson = JSON.parse(DetailData);
    var venueMnemonic = DetailJson.venueMnemonic;
    var raceType = DetailJson.raceType;
    var raceNumber = DetailJson.raceNumber;

}