Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share variable across multiple VUs #1726

Closed
hrai opened this issue Nov 18, 2020 · 1 comment
Closed

Share variable across multiple VUs #1726

hrai opened this issue Nov 18, 2020 · 1 comment
Labels

Comments

@hrai
Copy link

hrai commented Nov 18, 2020

I am using multiple VUs to make an auth call. For each VU, the auth call was being made which was not efficient. So I wanted to use a global variable to hold the token value. It seems like the global variable is global only for the VU.

I resolved this issue by using setup and teardown functions as mentioned here.

Example code below:

export function setup() {
  let token = token == null ? getAuthToken() : token;
  return token;
}

export default function (token) {
  let requests = getRequests(token);
  .....

This should be documented so it's easier to find. I spent days trying to find a solution and this pointed me in the right direction

@mstoykov mstoykov added the docs label Nov 18, 2020
@mstoykov
Copy link
Contributor

Hi @hrai, I have already opened grafana/k6-docs#148 . I hope this is enough and ... that one day we actually sit down and write that documentation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants