Article From:https://www.cnblogs.com/changqing8023/p/9557563.html
from locust import TaskSet, task, HttpLocust


class UserBehavior(TaskSet):
def on_start(self): # When the analog user starts executing the TaskSet class, the on_start method is called.
self.index = 0

@task
def test_visit(self):
url = self.locust.share_data[
self.index] # Take self. locust. share_data & lt; equal to share_data & gt defined by the WebsiteUser class; the first element of self. index
self.index = (self.index + 1) % len(
self.locust.share_data) # self.index The value of the value is less than self.locust.share_data, which generates <, 0.1.2.3.4, 0.1.2.3.4... >
r = self.client.get(url) # TaskSetClass has a client attribute and returns self.locust.client
assert r.status_code == 200


class WebsiteUser(HttpLocust):
host = 'http://debugtalk.com'
task_set = UserBehavior
share_data = ['/', '/archives/', '/about/', '/archives/2018/05/', '/archives/2018/02/'] # Shared data, circular traversal usage
min_wait = 1000
max_wait = 3000

Leave a Reply

Your email address will not be published. Required fields are marked *