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

HttpLocust class instance variable not set for all users during setup #957

Closed
andylin00 opened this issue Feb 6, 2019 · 4 comments
Closed

Comments

@andylin00
Copy link

I have a question about how Locust works when specifying multiple users. I run locust --no-web -c 1 -r 1 expecting 2 users spawned at 1 user/sec. I see my HttpLocust-level setup() runs only once, so I assumed there is only 1 Locust instance regardless of number of users even though the output says that 2 ExampleLocusts hatch.

When the example task runs for the first user, everything prints out normally. When the example task runs for the second user, it prints "bye" and then "None" for the table instance variable. Why is my env instance variable saving the value and the table variable not?

Ty in advance.

Code:
`
class ExampleLocust:
task_set = basicTaskset
host = "whatever"
table = None
env = {}

setup() {
    self.env["hello"] = "bye"
    session = boto3.Session()
    dynamodb = session.resource('dynamodb', region_name='us-west-1')
    self.table = dynamodb.Table("exampleTable")

}

class ExampleTaskSet(TaskSequence):
tasks = [exampleTask]

def exampleTask(l):
print(l.locust.env["hello"])
print(l.locust.table)
`

@ltpitt
Copy link

ltpitt commented Mar 28, 2019

Hello @andvlin .

I have the same problem...

I load users from a file and then save them in a class variable.

1st user is reading it fine, for 2nd user it is empty.

How could you fix this issue?

Thanks and sorry for reviving this closed issue.

@andylin00
Copy link
Author

I just accepted that setup() in the HttpLocust class will only run once per program execution. I put any user-specific data I need to load in on_start() in the TaskSet / TaskSequence class

@ltpitt
Copy link

ltpitt commented Mar 28, 2019

Ah...
I've put some user generation code in setup() that saves its data into one main class variable.

But then as soon as the 2nd locust is zero the variable is reset :(

I cannot find a way to make a variable available for all the locusts without modification.

Sorry if I asked the wrong question here, then.

@aldenpeterson-wf
Copy link
Contributor

you can use global variables for that most likely @ltpitt

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

No branches or pull requests

3 participants