How to send vu.idInTest as same int to many function

const X = 10

export function a () {
 const  aID = X +  (vu.idInTest)
 .... ${aID }....
.....
};
export function b () {
 const  bID = X +  (vu.idInTest)
 .... ${bID }....
.....
};

and my scenarios is

scenarios: {
    scenarios1 : {
      executor: 'shared-iterations',
      exec: 'a',
      vus: 2,
      iterations: '2',
      startTime: '1s',
    },  
    scenarios2 : {
      executor: 'shared-iterations',
      exec: 'b',
      vus: 2,
      iterations: '2',
      startTime: '1s',
    },  

so aID send 11 , 12
and bID send 13 , 14 .

but I want bID to send 11 , 12 like aID. pls comment thank!.

not sure what you are trying to achieve or why but this code seems to do what you want?

import exec from 'k6/execution';

const X = 10;

 export const options = {
  scenarios: {
    scenarios1 : {
      executor: 'shared-iterations',
      exec: 'a',
      vus: 1,
      iterations: '10',
      startTime: '1s',
    },  
    scenarios2 : {
      executor: 'shared-iterations',
      exec: 'b',
      vus: 1,
      iterations: '10',
      startTime: '1s',
    },
 }
};


export function a () {
  let  aID = X +  exec.scenario.iterationInTest;
  console.log('sa: ' + exec.scenario.iterationInTest + ' : ' + aID);

 };
 export function b () {
  let  bID = X +  exec.scenario.iterationInTest;
  console.log('sb: ' + exec.scenario.iterationInTest + ' : ' + bID);
 };
INFO[0001] sb: 0 : 10                                    source=console
INFO[0001] sa: 0 : 10                                    source=console
INFO[0001] sa: 1 : 11                                    source=console
INFO[0001] sa: 2 : 12                                    source=console
INFO[0001] sb: 1 : 11                                    source=console
INFO[0001] sa: 3 : 13                                    source=console
INFO[0001] sa: 4 : 14                                    source=console
INFO[0001] sa: 5 : 15                                    source=console
INFO[0001] sb: 2 : 12                                    source=console
INFO[0001] sb: 3 : 13                                    source=console
INFO[0001] sa: 6 : 16                                    source=console
INFO[0001] sb: 4 : 14                                    source=console
INFO[0001] sa: 7 : 17                                    source=console
INFO[0001] sb: 5 : 15                                    source=console
INFO[0001] sa: 8 : 18                                    source=console
INFO[0001] sb: 6 : 16                                    source=console
INFO[0001] sa: 9 : 19                                    source=console
INFO[0001] sb: 7 : 17                                    source=console
INFO[0001] sb: 8 : 18                                    source=console
INFO[0001] sb: 9 : 19                                    source=console
1 Like

thank you! for the solution
let’s say that I want to test 2 functions that have to send an Id that is a unique key.
so if my DB has the newest id is 50 I will repress X = 50.
1)function a is to create a new doc.
2)function b is like adding some file to that doc.
after function a crate id 51,52,53,54,55 then
function b will add file to id 51,52,53,54,55 with same id
And I stuck with a problem with sending the same Id to 2 functions.

However, your comment works for me :heart_eyes: .
and this is my first js project, performance test tools so feel free to comment me with franky

thank you! :+1:

Indeed you are and it’s a perennial problem with performance testing on how to establish communications and data sharing, particularly uniqueness, with virtual users.

When i used loadrunner they had a tool Virtual Table Server (VTS) and jmeter has a built in Simple Table Server (STS) which have both proved useful. At one stage I wrote a node.js server to do so but I’m no node programmer and it was pretty limited.

Of late I’ve been impressed with redis and have used it for both jmeter and k6 scripts. It requires some technical knowledge around extensions and setup and running (and tuning) of redis. However, it’s pretty easy once you get the hang of it.

1 Like

thank! I will take a look at redis too!. :heart_eyes: