예제 #1
0
 def setUp(self):
     super(TestSocketIO, self).setUp()
     self.client = None
     self.server = SimpleSocketIOServer()
     self.server.run()
     gevent.sleep(0.5)
     global_stats.clear_all()
예제 #2
0
 def setUp(self):
     super(WebserverTestCase, self).setUp()
     self._web_server = gevent.pywsgi.WSGIServer(("127.0.0.1", 0), app, log=None)
     gevent.spawn(lambda: self._web_server.serve_forever())
     gevent.sleep(0.01)
     self.port = self._web_server.server_port
     global_stats.clear_all()
예제 #3
0
 def setUp(self):
     super(WebserverTestCase, self).setUp()
     self._web_server = gevent.pywsgi.WSGIServer(("127.0.0.1", 0), app, log=None)
     gevent.spawn(lambda: self._web_server.serve_forever())
     gevent.sleep(0.01)
     self.port = self._web_server.server_port
     global_stats.clear_all()
예제 #4
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)
예제 #5
0
 def test_204(self):
     global_stats.clear_all()
     s = FastHttpSession("http://127.0.0.1:%i" % self.port)
     r = s.get("/status/204")
     self.assertEqual(204, r.status_code)
     self.assertEqual(1,
                      global_stats.get("/status/204", "GET").num_requests)
     self.assertEqual(0,
                      global_stats.get("/status/204", "GET").num_failures)
예제 #6
0
    def setUp(self):
        super(TestLocustTaskStatistics, self).setUp()
        options = config.LocustConfig()
        options.update_config({'host': '127.0.0.1'})

        class User(WebLocust):
            pass

        self.locust = User(options)
        global_stats.clear_all()
예제 #7
0
 def test_connection_error(self):
     global_stats.clear_all()
     s = FastHttpSession("http://localhost:1")
     r = s.get("/", timeout=0.1)
     self.assertEqual(r.status_code, 0)
     self.assertEqual(None, r.content)
     self.assertEqual(1, len(global_stats.errors))
     self.assertTrue(isinstance(r.error, ConnectionRefusedError))
     self.assertTrue(
         isinstance(
             next(iter(global_stats.errors.values())).error,
             ConnectionRefusedError))
예제 #8
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
예제 #9
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
예제 #10
0
 def test_max_requests_failed_requests(self):
     class MyTaskSet(TaskSet):
         @task
         def my_task(self):
             self.client.get("/ultra_fast")
             self.client.get("/fail")
             self.client.get("/fail")
         
     class MyLocust(HttpLocust):
         host = "http://127.0.0.1:%i" % self.port
         task_set = MyTaskSet
         min_wait = 1
         max_wait = 1
         
     try:
         from locust.exception import StopLocust
         global_stats.clear_all()
         global_stats.max_requests = 3
         
         l = MyLocust()
         self.assertRaises(StopLocust, lambda: l.task_set(l).run())
         self.assertEqual(1, global_stats.num_requests)
         self.assertEqual(2, global_stats.num_failures)
         
         global_stats.clear_all()
         global_stats.max_requests = 2
         self.assertEqual(0, global_stats.num_requests)
         self.assertEqual(0, global_stats.num_failures)
         l.run()
         self.assertEqual(1, global_stats.num_requests)
         self.assertEqual(1, global_stats.num_failures)
     finally:
         global_stats.clear_all()
         global_stats.max_requests = None
예제 #11
0
    def test_max_requests_failed_requests(self):
        class MyTaskSet(TaskSet):
            @task
            def my_task(self):
                self.client.get("/ultra_fast")
                self.client.get("/fail")
                self.client.get("/fail")

        class MyLocust(HttpLocust):
            host = "http://127.0.0.1:%i" % self.port
            task_set = MyTaskSet
            min_wait = 1
            max_wait = 1

        try:
            from locust.exception import StopLocust
            global_stats.clear_all()
            global_stats.max_requests = 3

            l = MyLocust()
            self.assertRaises(StopLocust, lambda: l.task_set(l).run())
            self.assertEqual(1, global_stats.num_requests)
            self.assertEqual(2, global_stats.num_failures)

            global_stats.clear_all()
            global_stats.max_requests = 2
            self.assertEqual(0, global_stats.num_requests)
            self.assertEqual(0, global_stats.num_failures)
            l.run()
            self.assertEqual(1, global_stats.num_requests)
            self.assertEqual(1, global_stats.num_failures)
        finally:
            global_stats.clear_all()
            global_stats.max_requests = None
예제 #12
0
    def test_max_requests(self):
        options = config.LocustConfig()
        options.update_config({'host': '127.0.0.1', 'port': self.port})

        class MyTaskSet(TaskSet):
            @task
            def my_task(self):
                self.client.http.get("/ultra_fast")

        class MyLocust(WebLocust):
            task_set = MyTaskSet
            min_wait = 1
            max_wait = 1

        try:
            from locust.exception import StopLocust
            global_stats.clear_all()
            global_stats.max_requests = 2

            l = MyLocust(options)
            self.assertRaises(StopLocust, lambda: l.task_set(l).run())
            self.assertEqual(2, global_stats.num_requests)

            global_stats.clear_all()
            global_stats.max_requests = 2
            self.assertEqual(0, global_stats.num_requests)

            l.run()
            self.assertEqual(2, global_stats.num_requests)
        finally:
            global_stats.clear_all()
            global_stats.max_requests = None
예제 #13
0
 def tearDown(self):
     global_stats.clear_all()