當前位置: 首頁>>代碼示例>>Python>>正文


Python locust.task方法代碼示例

本文整理匯總了Python中locust.task方法的典型用法代碼示例。如果您正苦於以下問題:Python locust.task方法的具體用法?Python locust.task怎麽用?Python locust.task使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在locust的用法示例。


在下文中一共展示了locust.task方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_start

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def on_start(self):
        """
        on_start is called when a Locust start before any task is scheduled
        """
        self.trafic_flow_observers = 0
        self.insert_traffic_flow_observed()

        self.air_quality_observers = 0
        self.insert_air_quality_observed() 
開發者ID:smartsdk,項目名稱:ngsi-timeseries-api,代碼行數:11,代碼來源:locustfile.py

示例2: index

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def index(self):
        self.client.get("/hello-world")

        # @task(1)
        # def about(self):
        #     self.client.get("/hello") 
開發者ID:karldoenitz,項目名稱:karlooper,代碼行數:8,代碼來源:test_case.py

示例3: purchase_single_free_product

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def purchase_single_free_product(self):
        """Simulate the purchase of a single free product via the LMS."""
        # If a user tries to purchase the same product more than once, we'll get 409s from
        # the LMS. To avoid this situation, we create a new user each time this task is called.
        self.auto_auth()

        post_data = {
            'course_id': settings.data['ecommerce']['free_course_id'],
        }
        self.post('/api/commerce/v0/baskets/', data=json.dumps(post_data)) 
開發者ID:edx-unsupported,項目名稱:edx-load-tests,代碼行數:12,代碼來源:baskets.py

示例4: get_ecom_worker_client

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def get_ecom_worker_client():
    """
    Gets the ecommerce worker client

    Using the oauth credentials in the settings file, this method
    returns up the ecommerce work clients which enables a task to call
    the api on behalf of the ecommerce worker.

    Returns:
        LocustEdxRestApiClient: The ecommerce worker client
    """
    access_token_endpoint = '{}/oauth2/access_token'.format(
        settings.secrets['oauth']['provider_url'].strip('/')
    )

    access_token, __ = LocustEdxRestApiClient.get_oauth_access_token(
        access_token_endpoint,
        settings.secrets['oauth']['client_id'],
        settings.secrets['oauth']['client_secret'],
    )

    return LocustEdxRestApiClient(
        ECOMMERCE_HOST,
        session=HttpSession(base_url=ECOMMERCE_HOST),
        oauth_access_token=access_token
    ) 
開發者ID:edx-unsupported,項目名稱:edx-load-tests,代碼行數:28,代碼來源:ecommerce_user_tasks.py

示例5: patch_credential

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def patch_credential(self):
        """ Randomly picked the status for patching the credentials. In case of revoke status remove the
        record from the deque. Otherwise during rendering task it will return 404.
        """
        if not self._user_credentials:
            return

        credential_uuid = random.choice(self._user_credentials)
        status = random.choice(['awarded', 'revoked'])
        data = {'status': status}
        if status == 'revoked':
            self._user_credentials.remove(credential_uuid)
        self.user_credential_client.credentials(credential_uuid).patch(data=data, name='/api/v2/credentials/[uuid]') 
開發者ID:edx-unsupported,項目名稱:edx-load-tests,代碼行數:15,代碼來源:locustfile.py

示例6: on_start

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.url = "/predictions/fizbuz_package"
        self.headers = {"Content-Type": "application/json"} 
開發者ID:hhsecond,項目名稱:HandsOnDeepLearningWithPytorch,代碼行數:6,代碼來源:locustfile.py

示例7: test_it_renders_a_locustfile_template

# 需要導入模塊: import locust [as 別名]
# 或者: from locust import task [as 別名]
def test_it_renders_a_locustfile_template(self):
        a_name = "some_task"
        a_request = MagicMock(spec=Request)
        a_request.method = HttpMethod.GET
        a_request.url = MagicMock(spec=SplitResult)
        a_request.url.scheme = "some_scheme"
        a_request.url.hostname = "some_hostname"
        a_request.url.path = "some_path"
        a_request.url.geturl()
        a_request.url.geturl.return_value = "some_url"
        a_request.headers = {"a": "b"}
        a_request.name = None
        task = Task(a_name, a_request)
        scenario = Scenario(name="SomeScenario", children=[task], origin=None)
        scenario_group = Scenario(
            name="ScenarioGroup", children=[scenario], weight=2, origin=None
        )
        script = locustfile([scenario_group])
        expected = string.Template(
            f"""
# File automatically generated by Transformer v{__version__}:
# https://github.com/zalando-incubator/Transformer
import re
from distutils.version import LooseVersion
from locust import __version__
LOCUST_MAJOR_VERSION = LooseVersion(__version__).version[0]
if LOCUST_MAJOR_VERSION >= 1:
    from locust import HttpUser
    from locust import SequentialTaskSet
    from locust import TaskSet
    from locust import task
    HttpLocust = HttpUser
    TaskSequence = SequentialTaskSet
    def seq_task(_):
        return task
else:
    from locust import HttpLocust
    from locust import TaskSequence
    from locust import TaskSet
    from locust import seq_task
    from locust import task
class ScenarioGroup(TaskSet):
    @task(1)
    class SomeScenario(TaskSequence):
        @seq_task(1)
        def some_task(self):
            response = self.client.get(url='some_url', name='some_url', timeout=$TIMEOUT, allow_redirects=False, headers={{'a': 'b'}})
class LocustForScenarioGroup(HttpLocust):
    if LOCUST_MAJOR_VERSION >= 1:
        tasks = [ScenarioGroup]
    else:
        task_set = ScenarioGroup
    weight = 2
    min_wait = 0
    max_wait = 10
"""
        ).safe_substitute({"TIMEOUT": TIMEOUT})
        assert expected.strip() == script.strip() 
開發者ID:zalando-incubator,項目名稱:transformer,代碼行數:60,代碼來源:test_locust.py


注:本文中的locust.task方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。