Python Locust performance test: Locust parameter-ensure concurrency test data uniqueness, cycle through data

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.