How to use the locust.events.request_failure function in locust

To help you get started, we’ve selected a few locust examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redhat-developer / che-functional-tests / che-start-workspace / osioperf.py View on Github external
def waitForWorkspaceToStop(self, id):
    timeout_in_seconds = 60 if os.getenv("STOP_HARD_FAILURE_TIMEOUT") == None else int(os.getenv("STOP_HARD_FAILURE_TIMEOUT"))
    soft_timeout_seconds = 5 if os.getenv("STOP_SOFT_FAILURE_TIMEOUT") == None else int(os.getenv("STOP_SOFT_FAILURE_TIMEOUT"))
    isSoftFailure = False
    workspace_status = self.getWorkspaceStatus(id)
    while workspace_status != "STOPPED":
      now = time.time()
      elapsed_time = int(now - self.start)
      if elapsed_time > soft_timeout_seconds and isSoftFailure == False:
        self.log("Workspace stopping on "+self.clusterName+" failed with soft failure.")
        os.system(self.soft_stop_failure_cmd+" -o 1 >/dev/null 2>&1")
        isSoftFailure = True
      if elapsed_time > timeout_in_seconds:
        events.request_failure.fire(request_type="REPEATED_GET",
                                    name="stopWorkspace_"+self.clusterName,
                                    response_time=self._tick_timer(),
                                    exception="Workspace wasn't able to stop in " 
                                              + str(elapsed_time)
                                              + " seconds.")
        self.log("Workspace " + self.id + " wasn't able to stop in " 
                 + str(elapsed_time) + " seconds.")
        os.system(self.hard_stop_failure_cmd+" -o 1 >/dev/null 2>&1")
        return
      self.log("Workspace id " + id + " is still not in state STOPPED ["
               + workspace_status +"] {" + str(elapsed_time) + " of " + str(timeout_in_seconds) + "}")
      self.wait()
      workspace_status = self.getWorkspaceStatus(id)
    self.log("Workspace id " + id + " is STOPPED")
    events.request_success.fire(request_type="REPEATED_GET",
                                name="stopWorkspace_"+self.clusterName,
github opstree / redis-load-test / Scripts / redis_get_set.py View on Github external
def query(self, key, command='GET'):
        """Function to Test GET operation on Redis"""
        result = None
        start_time = time.time()
        try:
            result = self.rc.get(key)
            if not result:
                result = ''
        except Exception as e:
            total_time = int((time.time() - start_time) * 1000)
            events.request_failure.fire(request_type=command, name=key, response_time=total_time, exception=e)
        else:
            total_time = int((time.time() - start_time) * 1000)
            length = len(result)
            events.request_success.fire(request_type=command, name=key, response_time=total_time, response_length=length)
        return result
github redhat-developer / rh-che / load-tests / WSLocust.py View on Github external
def send_json_rpc(self, payload, task):
        start_time = time.time()
        if not self.connected:
            print("Client is not connected, cannot send request")
            events.request_failure.fire(request_type="send_payload",
                                        name="Send_payload_"+task,
                                        response_time=0,
                                        exception="Not connected.")
        try:
            self.ws.send(payload)
        except Exception as e:
            print(e)
            total_time = int((time.time() - start_time) * 1000)
            events.request_failure.fire(request_type="send_payload",
                                        name="Send_payload_"+task,
                                        response_time=total_time,
                                        exception=e)
            raise e
        else:
            total_time = int((time.time() - start_time) * 1000)
            events.request_success.fire(request_type="send_payload",
github karol-brejna-i / locust-experiments / sending-results / locust-scripts / locustfile.py View on Github external
json_string = OK_TEMPLATE % (request_type, name, "OK", response_time, response_length, json.dumps(kwargs))
        message = {"type": "success", "payload": json.loads(json_string)}
        forwarder.add(message)


    def additional_failure_handler(request_type, name, response_time, exception, **kwargs):
        """ additional request failure handler to log statistics """
        ERR_TEMPLATE = '{"request_type":"%s", "name":"%s", "result":"%s", ' \
                       '"response_time":%s, "exception":"%s", "other":%s}'
        json_string = ERR_TEMPLATE % (request_type, name, "ERR", response_time, exception, json.dumps(kwargs))
        message = {"type": "error", "payload": json.loads(json_string)}
        forwarder.add(message)


    events.request_success += additional_success_handler
    events.request_failure += additional_failure_handler


class TestBehaviour(TaskSet):
    @task
    def task1(self):
        gevent.spawn(self.client.put, f"/delay/{randint(0, 9)}", name="/delayed")

    @task
    def task2(self):
        self.client.get("/get")

    @task
    def task3(self):
        self.client.post("/post", json={"one": "two"})

    @task
github SeldonIO / seldon-server / docker / locust / scripts / seldon_grpc_predict_locust.py View on Github external
def get_prediction(self):
            channel = grpc.insecure_channel(self.grpc_endpoint)
            stub = seldon_pb2.SeldonStub(channel)
            fake_data = [random() for i in range(0,self.data_size)]
            data = seldon_pb2.DefaultCustomPredictRequest(values=fake_data)
            dataAny = any_pb2.Any()
            dataAny.Pack(data)
            meta = seldon_pb2.ClassificationRequestMeta(puid=str(randint(0,99999999)))
            metadata = [(b'oauth_token', self.token)]
            request = seldon_pb2.ClassificationRequest(meta=meta,data=dataAny)
            start_time = time.time()
            try:
                reply = stub.Classify(request,999,metadata=metadata)
            except xmlrpclib.Fault as e:
                total_time = int((time.time() - start_time) * 1000)
                events.request_failure.fire(request_type="grpc", name=HOST, response_time=total_time, exception=e)
            else:
                total_time = int((time.time() - start_time) * 1000)
                events.request_success.fire(request_type="grpc", name=HOST, response_time=total_time, response_length=0)
github httprunner / HttpRunnerManager / httprunner / task.py View on Github external
def run(self):
        for test_suite in self.test_suite_list:
            for test in test_suite:
                try:
                    test.runTest()
                except exception.MyBaseError as ex:
                    from locust.events import request_failure
                    request_failure.fire(
                        request_type=test.testcase_dict.get("request", {}).get("method"),
                        name=test.testcase_dict.get("request", {}).get("url"),
                        response_time=0,
                        exception=ex
                    )
github lovesoo / Taffy / Tests / locustfile.py View on Github external
try:
            test_demo().test_httpbin_post()
            request_type = test_demo.__name__
            name = test_demo().test_httpbin_post.__name__
        except Exception as e:
            total_time = int((time.time() - start_time) * 1000)
            events.request_failure.fire(request_type=request_type, name=name, response_time=total_time, exception=e)
        else:
            total_time = int((time.time() - start_time) * 1000)
            events.request_success.fire(request_type=request_type, name=name, response_time=total_time, response_length=0)



    def test_demo_test_webservice(self):
        start_time = time.time()
github locustio / locust / examples / custom_xmlrpc_client / xmlrpc_locustfile.py View on Github external
def wrapper(*args, **kwargs):
            start_time = time.time()
            try:
                result = func(*args, **kwargs)
            except xmlrpclib.Fault as e:
                total_time = int((time.time() - start_time) * 1000)
                events.request_failure.fire(request_type="xmlrpc", name=name, response_time=total_time, exception=e)
            else:
                total_time = int((time.time() - start_time) * 1000)
                events.request_success.fire(request_type="xmlrpc", name=name, response_time=total_time, response_length=0)
                # In this example, I've hardcoded response_length=0. If we would want the response length to be 
github locustio / locust / locust / clients.py View on Github external
"""
        Report the response as a failure.
        
        exc can be either a python exception, or a string in which case it will
        be wrapped inside a CatchResponseError. 
        
        Example::
        
            with self.client.get("/", catch_response=True) as response:
                if response.content == b"":
                    response.failure("No data")
        """
        if isinstance(exc, six.string_types):
            exc = CatchResponseError(exc)
        
        events.request_failure.fire(
            request_type=self.locust_request_meta["method"],
            name=self.locust_request_meta["name"],
            response_time=self.locust_request_meta["response_time"],
            response_length=self.locust_request_meta["content_size"],
            exception=exc,
        )
        self._is_reported = True
github nseinlet / OdooLocust / OdooLocust / OdooLocust.py View on Github external
def send(self, service_name, method, *args):
    if service_name=="object" and method=="execute_kw":
        call_name = "%s : %s" % args[3:5]
    else:
        call_name = '%s : %s' % (service_name, method)
    start_time = time.time()
    try:
        res = openerplib.json_rpc(self.url, "call", {"service": service_name, "method": method, "args": args})
    except Exception as e:
        total_time = int((time.time() - start_time) * 1000)
        events.request_failure.fire(request_type="Odoo JsonRPC", name=call_name, response_time=total_time, exception=e)
        raise e
    else:
        total_time = int((time.time() - start_time) * 1000)
        events.request_success.fire(request_type="Odoo JsonRPC", name=call_name, response_time=total_time, response_length=sys.getsizeof(res))
    return res