'Have user continue to run test in step load after x amount of users have ramped up (python) (locust)
My use case is as below: I am trying to run a test programmatically where in i want users to ramp up to a certain amount of users. Then once the ramp up is finished i want the combined ramped up users to continue the test for an hour.
Below is the code, by which i can have users (5 in total) ramp up until time_limit (300) is reached. Now i want to have these users run for an hour after the ramping up has finished. Any suggestions what changes i need to make to the code?
import math
from locust import HttpUser, TaskSet, task, constant
from locust import LoadTestShape
class StepLoadShape(LoadTestShape):
"""
A step load shape
Keyword arguments:
step_time -- Time between steps
step_load -- User increase amount at each step
spawn_rate -- Users to stop/start per second at every step
time_limit -- Time limit in seconds
"""
# this below config led to 5 users in total
step_time = 60
step_load = 1
spawn_rate = 1
time_limit = 300
def tick(self):
run_time = self.get_run_time()
if run_time > self.time_limit:
return None
current_step = math.floor(run_time / self.step_time) + 1
return (current_step * self.step_load, self.spawn_rate)
class UserBehavior(HttpUser):
wait_time=constant(1)
host="https://google.com"
@task
def launch_URL(self):
token = "XXXXXXXXXXX"
headers={
"Content-Type":"application/json",
"Authorization":"Bearer " + token,
"id":"TEST_QA"}
with self.client.get("/google.com?clientId=test&userId=user_1",headers=headers,catch_response=True) as response:
if ("Descriptor") in response.json():
if response.status_code == 200:
response.success()
else:
response.failure("HTTP 200OK not received")
else:
response.failure("Valid response not returned")
Solution 1:[1]
Yes i am checking that and did replace that with response.text() and that fixed it. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Contraboy |
