def login(self): username = str(random.randint(0, n_users)) password = "******" + username with self.client.post('register', json={ 'username': username, 'password': password }, catch_response=True) as resp: if resp: if resp.status_code == 409: self.client.id = str( self.client.post('login', json={ 'username': username, 'password': password }, catch_response=True).json()['id']) resp.success() else: if resp.status_code == 200: self.client.id = str(resp.json()['id']) resp.success() else: resp.failure("Error {0}".format(resp.status_code)) raise InterruptTaskSet() else: resp.failure('Got no response')
def get_run(self, run_name): logging.info("Run Get: STARTED - %s", run_name) try: resource = self.api.get_namespaced_custom_object( group=K8_GROUP, version=VERSION, name=run_name, namespace="default", plural="runs", ) except ApiException as e: logging.error("API Exception: %s\n" % e) raise InterruptTaskSet(reschedule=False) return resource
def delete_run(self, run_name): logging.info("Run Deletion: STARTED - %s", run_name) try: self.api.delete_namespaced_custom_object( group=K8_GROUP, version=VERSION, name=run_name, namespace="default", plural="runs", body=client.V1DeleteOptions(), ) except ApiException as e: logging.error("API Exception: %s\n" % e) raise InterruptTaskSet(reschedule=False) logging.info("Run Deletion: COMPLETE - %s", run_name)
def create_run(self): logging.info("Run Creation: STARTED") run_name = "run-{}".format(str(uuid.uuid4())) run = copy.deepcopy(RUN_RESOURCE) run["metadata"]["name"] = run_name try: self.api.create_namespaced_custom_object( group=K8_GROUP, version=VERSION, namespace="default", plural="runs", body=run, ) except ApiException as e: logging.error("API Exception: %s\n" % e) raise InterruptTaskSet(reschedule=False) logging.info("Run Creation: COMPLETE - {}".format(run_name)) return run_name
def handle_message(self, msg, **kwargs): init_time = kwargs.get('init_time', time.time()) if "CONNECTED" in msg: logging.info("%s: Connection initiated", self.instanceId) request_success.fire(request_type='WebSocket Init', name='Init websocket connection', response_time=(time.time() - init_time) * 1000, response_length=len(msg)) elif "ERROR" in msg: logging.warning("%s: Received error: \n %s", self.instanceId, str(msg)) request_failure.fire(request_type='WebSocket Error', name='Websocket server Error', response_time=(time.time() - init_time) * 1000, response_length=len(msg), exception=InterruptTaskSet()) raise StopLocust() elif "MESSAGE" in msg: logging.info("%s: Message received: %s", self.instanceId, str(msg)) message = str(msg) idx = message.find("{") content = message[idx:-1] json_msg = json.loads(content) res = stomper.send( "/app/device", '{ "time": "' + datetime.datetime.now().isoformat() + '",' + '"status": "OK",' + '"id": "' + json_msg["id"] + '",' + '"data": ' + str([1, 0, -1, 0]) + '}', content_type="application/json") self.ws.send(res) request_success.fire(request_type='Msg Receive', name='Msg received', response_time=(time.time() - init_time) * 1000, response_length=len(msg))
def t2(self): self.t2_executed = True raise InterruptTaskSet(reschedule=False)
def interrupted_task(self): with self.client.get("/ultra_fast", catch_response=True) as r: raise InterruptTaskSet()
def interrupted_task(self): raise InterruptTaskSet(reschedule=False)
def t3(self): if self._index == 0: self.t3_executed += 1 raise InterruptTaskSet(reschedule=False)
def t3(l): if l._index == 0: l.t3_executed = True raise InterruptTaskSet(reschedule=False)
def t1(self): test.assertTrue(self.context['default'] == 10) raise InterruptTaskSet(reschedule=False)
def t1(self): test.assertTrue(self.context['default'] == 2) self.context['default'] += 1 self.completed += 1 if self.completed >= 2: raise InterruptTaskSet(reschedule=False)
def t1(self): test.assertTrue(self.context['any'] == 2) self.context['any'] += 1 raise InterruptTaskSet(reschedule=False)
def t1(self): test.assertTrue(self.context['any_4'] == None) raise InterruptTaskSet(reschedule=False)