mercredi 11 novembre 2020

K6: Authorization in the Test Life Cycle

I have been reading through the K6 documentation and am struggling to find a way to conform a K6 script to meet my needs. The scenario I imagine in my head:

// 1. init code
export function setup() {
  // 2. setup code
  // The VU would get setup here with authentication once
}
export default function (data) {
  // 3. VU code
  // The VU would run this code a repeated amount of times
}
export function teardown(data) {
  // 4. teardown code
  // The VU would be deauthed here after the VU code has ran its course

Unfortunately, from what I've read here: https://k6.io/docs/using-k6/test-life-cycle, my understanding is that the above scenario isn't possible. "setup is called at the beginning of the test, after the init stage but before the VU stage (default function), and teardown is called at the end of a test, after the VU stage (default function). Therefore, VU number is 0 while executing the setup and teardown functions." I interpret this to mean that in the above scenario, all the VU's would use the same authentication to run the VU code instead of each VU getting it's own separate authentication.

If I simply exclude the setup and teardown sections, then each VU would get new authentication on each loop:

export default function (data) {
  // 3. VU code
  // VU gets authenticated
  // VU does a bunch of stuff
  // VU clears authentication
}

Is there a way to design K6 scripts with my intention (VU Authenticates once -> VU code loop -> Deauth at the end once)?

Aucun commentaire:

Enregistrer un commentaire