From locust import TaskSet, task, Httplocust
Import queue
Class Userbehavior (TaskSet):
@task
def test_register (self):
Try
# get_nowait () does not take data directly crashes; get () No data will wait
data = Self.locust.user_data_queue.get_nowait () # Value order ' username ': ' test0000 ', ' username ': ' test0001 ', ' username ': ' Test0002 ' ...
Except queue. Empty: # When the data is not taken, go here
Print (' account data run out, test ended. ')
Exit (0)
Print (' Register with User: {}, pwd: {} '. Format (data[' username '), data[' password '))
Payload = {
' username ': data[' username '],
' Password ': data[' password ']
}
r = Self.client.post ('/user/signin?returnurl=https%3a%2f%2fwww.cnblogs.com%2f ', data=payload)
self.locust.user_data_queue.put_nowait (data)# to rejoin the data that was taken out of the queue
Assert R.status_code = = 200
Class Websiteuser (Httplocust):
Host = ' https://passport.cnblogs.com '
Task_set = Userbehavior
User_data_queue = queue. Queue () # Create queues, FIFO
For index in range (100):
data = {
"username": "test%04d"% index,
"Password": "pwd%04d"% index,
"Email": "Test%[email protected]"% index,
"Phone": "186%08d"% index,
}
User_data_queue.put_nowait (data) # Loop join queue < All;, loop, continue execution
min_wait = 1000
max_wait = 3000
Reference: http://debugtalk.com/post/head-first-locust-advanced-script/
Python Locust performance test: Locust parameter-ensure concurrency test data uniqueness, cycle through data