Multiple simplifies data sharing across your load test stages, allowing the transfer of variables and data from Global Init and VU Init to later test phases. This flow makes it easy to manage authentication tokens, maintain database and websocket connections,and simulate realistic usage patterns.

Any type of value can be passed from VU Init, but the value passed from Global Init must be JSON-serializable.

To pass data down to other stages from Global Init or VU Init, return the value from the function. It is then accessible via ctx.globalInitData and ctx.vuInitData respectively.

For instance, in our MongoDB example, PARAMS are defined and returned in globalInit():

 async globalInit(ctx) {
    // Set parameters for the test
    const PARAMS = {
      DB_NAME: `temp-db-${Date.now()}`,
      COLLECTION_NAME: `temp-collection-${Date.now()}`,
      INSERT_PCT: 100, // MUST BE BETWEEN 0 and 100
      UPDATE_PCT: 70, // MUST BE BETWEEN 0 and 100
      DELETE_PCT: 50, // MUST BE BETWEEN 0 and 100
    };

    // ... rest of the code

    return {
      PARAMS,
    };
 }

PARAMS are then used by vuInit():

async vuInit(ctx) {
  // Get PARAMS from globalInit()
  const { DB_NAME, COLLECTION_NAME } = ctx.globalInitData.PARAMS;

  // ... rest of the code
}

And then again, by the vuLoop():

async vuLoop(ctx) {
  // Get PARAMS from globalInit()
  const { INSERT_PCT, UPDATE_PCT, DELETE_PCT } = ctx.globalInitData.PARAMS;

  // ... rest of the code
}

The example above highlights how data is passed between stages using ctx.globalInitData.PARAMS.