diff options
Diffstat (limited to 'benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py')
-rw-r--r-- | benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py b/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py new file mode 100644 index 000000000000..6f8f66baa5ca --- /dev/null +++ b/benchmarks/py-locust/files/extra-EXAMPLES-dynamice_user_credentials.py @@ -0,0 +1,25 @@ +# locustfile.py + +from locust import HttpLocust, TaskSet, task + +USER_CREDENTIALS = [ + ("user1", "password"), + ("user2", "password"), + ("user3", "password"), +] + +class UserBehaviour(TaskSet): + def on_start(self): + if len(USER_CREDENTIALS) > 0: + user, passw = USER_CREDENTIALS.pop() + self.client.post("/login", {"username":user, "password":passw}) + + @task + def some_task(self): + # user should be logged in here (unless the USER_CREDENTIALS ran out) + self.client.get("/protected/resource") + +class User(HttpLocust): + task_set = UserBehaviour + min_wait = 5000 + max_wait = 60000 |