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 '))
BODY = {
' username ': data[' username '],
' Password ': data[' password ']
}
r = Self.client.post ('/user/signin ', data=body). Text
Assert R.status_code = = 200
Class Websiteuser (Httplocust):
Host = ' https://passport.cnblogs.com '
Task_set = Userbehavior
User_data_queue = queue. Queue (maxsize=100) # 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: Locsut parameterization-ensures concurrency test data uniqueness and does not cycle through data