Beispiel #1
0
 def test_request_connection_error(self):
     class MyLocust(HttpLocust):
         host = "http://localhost:1"
     
     locust = MyLocust()
     response = locust.client.get("/", timeout=0.1)
     assert response.status_code == 0
     assert 1 == global_stats.get("/", "GET").num_failures
     assert 0 == global_stats.get("/", "GET").num_requests
Beispiel #2
0
 def test_request_connection_error(self):
     class MyLocust(HttpLocust):
         host = "http://localhost:1"
     
     locust = MyLocust()
     response = locust.client.get("/", timeout=0.1)
     self.assertEqual(response.status_code, 0)
     self.assertEqual(1, global_stats.get("/", "GET").num_failures)
     self.assertEqual(0, global_stats.get("/", "GET").num_requests)
Beispiel #3
0
 def test_post_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect"
     r = s.post(url)
     self.assertEqual(200, r.status_code)
     post_stats = global_stats.get(url, method="POST")
     get_stats = global_stats.get(url, method="GET")
     self.assertEqual(1, post_stats.num_requests)
     self.assertEqual(0, get_stats.num_requests)
Beispiel #4
0
 def test_request_stats_content_length(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.get("/ultra_fast")
     self.assertEqual(global_stats.get("/ultra_fast", "GET").avg_content_length, len("This is an ultra fast response"))
     locust.client.get("/ultra_fast")
     self.assertEqual(global_stats.get("/ultra_fast", "GET").avg_content_length, len("This is an ultra fast response"))
Beispiel #5
0
 def test_post_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect"
     r = s.post(url)
     assert 200 == r.status_code
     post_stats = global_stats.get(url, method="POST")
     get_stats = global_stats.get(url, method="GET")
     assert 1 == post_stats.num_requests
     assert 0 == get_stats.num_requests
Beispiel #6
0
    def test_redirect_url_original_path_as_name(self):
        class MyLocust(HttpLocust):
            host = "http://127.0.0.1:%i" % self.port

        l = MyLocust()
        l.client.get("/redirect")
        
        from locust.stats import global_stats
        self.assertEqual(1, len(global_stats.entries))
        self.assertEqual(1, global_stats.get("/redirect", "GET").num_requests)
        self.assertEqual(0, global_stats.get("/ultra_fast", "GET").num_requests)
Beispiel #7
0
 def test_request_stats_no_content_length_no_prefetch(self):
     class MyLocust(Locust):
         host = "http://127.0.0.1:%i" % self.port
     l = MyLocust()
     path = "/no_content_length"
     r = l.client.get(path, prefetch=False)
     self.assertEqual(0, global_stats.get(path, "GET").avg_content_length)
Beispiel #8
0
    def test_request_stats_put(self):
        class MyLocust(HttpLocust):
            host = "http://127.0.0.1:%i" % self.port

        locust = MyLocust()
        locust.client.put("/put")
        self.assertEqual(1, global_stats.get("/put", "PUT").num_requests)
Beispiel #9
0
 def test_request_stats_put(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.put("/put")
     self.assertEqual(1, global_stats.get("/put", "PUT").num_requests)
Beispiel #10
0
 def test_request_stats_no_content_length(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
     l = MyLocust()
     path = "/no_content_length"
     r = l.client.get(path)
     self.assertEqual(global_stats.get(path, "GET").avg_content_length, len("This response does not have content-length in the header"))
Beispiel #11
0
 def test_request_stats_named_endpoint(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.get("/ultra_fast", name="my_custom_name")
     self.assertEqual(1, global_stats.get("my_custom_name", "GET").num_requests)
Beispiel #12
0
 def test_request_stats_named_endpoint(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.get("/ultra_fast", name="my_custom_name")
     self.assertEqual(1, global_stats.get("my_custom_name", "GET").num_requests)
Beispiel #13
0
 def test_request_stats_query_variables(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.get("/ultra_fast?query=1")
     self.assertEqual(1, global_stats.get("/ultra_fast?query=1", "GET").num_requests)
Beispiel #14
0
 def test_request_stats_no_content_length(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
     l = MyLocust()
     path = "/no_content_length"
     r = l.client.get(path)
     self.assertEqual(global_stats.get(path, "GET").avg_content_length, len("This response does not have content-length in the header"))
Beispiel #15
0
 def test_request_stats_no_content_length_streaming(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
     l = MyLocust()
     path = "/no_content_length"
     r = l.client.get(path, stream=True)
     self.assertEqual(0, global_stats.get(path, "GET").avg_content_length)
Beispiel #16
0
 def test_slow_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect?url=/redirect?delay=0.5"
     r = s.get(url)
     stats = global_stats.get(url, method="GET")
     self.assertEqual(1, stats.num_requests)
     self.assertGreater(stats.avg_response_time, 500)
Beispiel #17
0
 def test_request_stats_query_variables(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
 
     locust = MyLocust()
     locust.client.get("/ultra_fast?query=1")
     self.assertEqual(1, global_stats.get("/ultra_fast?query=1", "GET").num_requests)
Beispiel #18
0
 def test_request_stats_no_content_length_streaming(self):
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
     l = MyLocust()
     path = "/no_content_length"
     r = l.client.get(path, stream=True)
     self.assertEqual(0, global_stats.get(path, "GET").avg_content_length)
Beispiel #19
0
 def test_slow_redirect(self):
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     url = "/redirect?url=/redirect?delay=0.5"
     r = s.get(url)
     stats = global_stats.get(url, method="GET")
     assert 1 == stats.num_requests
     assert stats.avg_response_time > 500
Beispiel #20
0
    def test_log_request_name_argument(self):
        from locust.stats import global_stats
        self.response = ""
        
        class MyLocust(HttpLocust):
            tasks = []
            host = "http://127.0.0.1:%i" % self.port
            
            @task()
            def t1(l):
                self.response = l.client.get("/ultra_fast", name="new name!")

        my_locust = MyLocust()
        my_locust.t1()
        
        self.assertEqual(1, global_stats.get("new name!", "GET").num_requests)
        self.assertEqual(0, global_stats.get("/ultra_fast", "GET").num_requests)
Beispiel #21
0
    def test_log_request_name_argument(self):
        from locust.stats import global_stats
        self.response = ""
        
        class MyLocust(HttpLocust):
            tasks = []
            host = "http://127.0.0.1:%i" % self.port
            
            @task()
            def t1(l):
                self.response = l.client.get("/ultra_fast", name="new name!")

        my_locust = MyLocust()
        my_locust.t1()
        
        self.assertEqual(1, global_stats.get("new name!", "GET").num_requests)
        self.assertEqual(0, global_stats.get("/ultra_fast", "GET").num_requests)
Beispiel #22
0
 def test_404(self):
     global_stats.clear_all()
     s = FastHttpSession("http://127.0.0.1:%i" % self.port)
     r = s.get("/does_not_exist")
     self.assertEqual(404, r.status_code)
     self.assertEqual(
         1,
         global_stats.get("/does_not_exist", "GET").num_failures)
Beispiel #23
0
 def test_streaming_response(self):
     """
     Test a request to an endpoint that returns a streaming response
     """
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.get("/streaming/30")
     
     # verify that the time reported includes the download time of the whole streamed response
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     global_stats.clear_all()
     
     # verify that response time does NOT include whole download time, when using stream=True
     r = s.get("/streaming/30", stream=True)
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 0)
     self.assertLess(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     
     # download the content of the streaming response (so we don't get an ugly exception in the log)
     _ = r.content
Beispiel #24
0
 def test_streaming_response(self):
     """
     Test a request to an endpoint that returns a streaming response
     """
     s = HttpSession("http://127.0.0.1:%i" % self.port)
     r = s.get("/streaming/30")
     
     # verify that the time reported includes the download time of the whole streamed response
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     global_stats.clear_all()
     
     # verify that response time does NOT include whole download time, when using stream=True
     r = s.get("/streaming/30", stream=True)
     self.assertGreater(global_stats.get("/streaming/30", method="GET").avg_response_time, 0)
     self.assertLess(global_stats.get("/streaming/30", method="GET").avg_response_time, 250)
     
     # download the content of the streaming response (so we don't get an ugly exception in the log)
     _ = r.content
Beispiel #25
0
    def test_log_request_name_argument(self):
        from locust.stats import global_stats
        self.response = ""

        class MyLocust(WebLocust):
            tasks = []
            pass

            @task()
            def t1(l):
                self.response = l.client.http.get("/ultra_fast",
                                                  name="new name!")

        options = config.LocustConfig()
        options.update_config({'host': '127.0.0.1', 'port': self.port})
        my_locust = MyLocust(options)
        my_locust.t1()

        self.assertEqual(
            1,
            global_stats.get(None, "new name!", "GET").num_requests)
        self.assertEqual(
            0,
            global_stats.get(None, "/ultra_fast", "GET").num_requests)
Beispiel #26
0
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)
Beispiel #27
0
 def test_request_stats_no_content_length(self):
     path = "/no_content_length"
     r = self.locust.client.http.get(path)
     self.assertEqual(
         global_stats.get(None, path, "GET").avg_content_length,
         len("This response does not have content-length in the header"))
Beispiel #28
0
 def test_failure(self):
     self.client.failure('01', 'Test Error')
     stats = global_stats.get('/RPC2', 'xmlrpc')
     self.assertEqual(stats.num_failures, 1)
Beispiel #29
0
 def test_request_stats_named_endpoint(self):
     self.locust.client.http.get("/ultra_fast", name="my_custom_name")
     self.assertEqual(
         1,
         global_stats.get(None, "my_custom_name", "GET").num_requests)
Beispiel #30
0
 def test_failure_not_found(self):
     self.client.method_doesnt_exist()
     stats = global_stats.get('/RPC2', 'xmlrpc')
     self.assertEqual(stats.num_failures, 1)
Beispiel #31
0
 def test_request_stats_put(self):
     self.locust.client.http.put("/put")
     self.assertEqual(1, global_stats.get(None, "/put", "PUT").num_requests)
Beispiel #32
0
 def test_returns_something(self):
     res = self.client.add(2, 2)
     self.assertEqual(res, 4)
     stats = global_stats.get('/RPC2', 'xmlrpc')
     self.assertEqual(stats.num_requests, 1)
Beispiel #33
0
 def test_request_stats_no_content_length_streaming(self):
     path = "/no_content_length"
     r = self.locust.client.http.get(path, stream=True)
     self.assertEqual(
         0,
         global_stats.get(None, path, "GET").avg_content_length)
Beispiel #34
0
 def test_request_stats_query_variables(self):
     self.locust.client.http.get("/ultra_fast?query=1")
     self.assertEqual(
         1,
         global_stats.get(None, "/ultra_fast?query=1", "GET").num_requests)