Exemplo n.º 1
0
    def test_error_message_with_name_replacment(self):
        s = HttpSession("http://127.0.0.1:%i" % self.port)
        my_event = events.EventHook()
        kwargs = {}

        def on_my_event(**kw):
            kwargs.update(kw)

        my_event += on_my_event
        orig_events = events.request_failure
        events.request_failure = my_event
        s.request('get', '/wrong_url/01', name='replaced_url_name')
        events.request_failure = orig_events
        self.assertIn('for url: replaced_url_name', str(kwargs['exception']))
Exemplo n.º 2
0
from locust.stats import global_stats
import socket
import requests


def unused_tcp_port():
    with contextlib.closing(socket.socket()) as sock:
        sock.bind(('', 0))
        return sock.getsockname()[1]


def myip():
    return requests.get('http://ip.42.pl/raw').text


notification_event = events.EventHook()


def notification_event_handler(path, request_type, request):
    # count the number of times a subscription_uuid is hit
    # count the number of times a bundle is hit for a subscription_uuid
    notification_id = path.split('/')[-1]
    # req = request.json()
    global_stats.get(f"notification {notification_id}", request_type).log(0, 0)


class NotifcationHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        notification_event.fire(path=self.path, request_type=self.command, request=self.request)
        self.send_response(200)
        self.end_headers()
Exemplo n.º 3
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Jonny"
# Email: [email protected]
# Date: 2017/10/20
from locust import Locust, TaskSet, events, task

mars_event = events.EventHook()


def mars_special_event(verb='', content=''):
    print('mars %s %s' % (verb, content))


mars_event += mars_special_event


class UserTask(TaskSet):
    @task(1)
    def job1(self):
        mars_event.fire(verb='love', content='locust')

    @task(3)
    def job2(self):
        print("In job2 ...")


class User(Locust):
    task_set = UserTask
    min_wait = 3000
    max_wait = 5000