本文整理匯總了Python中locust.Locust方法的典型用法代碼示例。如果您正苦於以下問題:Python locust.Locust方法的具體用法?Python locust.Locust怎麽用?Python locust.Locust使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類locust
的用法示例。
在下文中一共展示了locust.Locust方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: teardown
# 需要導入模塊: import locust [as 別名]
# 或者: from locust import Locust [as 別名]
def teardown(self):
print("Locust ends his tasks")
示例2: __init__
# 需要導入模塊: import locust [as 別名]
# 或者: from locust import Locust [as 別名]
def __init__(self, *args, **kwargs):
super(Locust, self).__init__(*args, **kwargs)
if self.host is None:
raise LocustError("You must specify a host")
#TODO: Current implementation sets an empty client_id when the connection is initialized,
# which Paho handles by creating a random client_id.
# Ideally we want to control the client_id that is set in Paho. Each client_id
# should match a thing_id in the AWS IoT Thing Registry
#self.client = MQTTClient(self.client_id)
self.client = MQTTClient()
try:
[host, port] = self.host.split(":")
except:
host, port = self.host, 8883
try:
self.client.tls_set(self.ca_cert, self.iot_cert, self.iot_private_key, tls_version=ssl.PROTOCOL_TLSv1_2)
#It is important to do an asynchronous connect, given that we will have
#multiple connections happening in a single server during a Locust test
self.client.connect_async(host, port)
self.client.loop_start()
except Exception as e:
fire_locust_failure(
request_type=REQUEST_TYPE,
name='connect',
response_time=time_delta(start_time, time.time()),
exception=ConnectError("Could not connect to host:["+host+"]")
)