Ejemplo n.º 1
0
    def test_no_reset_stats(self):
        class MyUser(User):
            wait_time = constant(0)

            @task
            class task_set(TaskSet):
                @task
                def my_task(self):
                    self.user.environment.events.request_success.fire(
                        request_type="GET",
                        name="/test",
                        response_time=666,
                        response_length=1337,
                    )
                    sleep(2)

        environment = Environment(reset_stats=False, user_classes=[MyUser])
        runner = LocalRunner(environment)
        runner.start(user_count=6, hatch_rate=12, wait=False)
        sleep(0.25)
        self.assertGreaterEqual(
            runner.stats.get("/test", "GET").num_requests, 3)
        sleep(0.3)
        self.assertEqual(6, runner.stats.get("/test", "GET").num_requests)
        runner.quit()
Ejemplo n.º 2
0
 def test_change_user_count_during_hatching(self):
     class MyUser(User):
         wait_time = constant(1)
         @task
         def my_task(self):
             pass
     
     environment = Environment(user_classes=[MyUser])
     runner = LocalRunner(environment)
     runner.start(user_count=10, hatch_rate=5, wait=False)
     sleep(0.6)
     runner.start(user_count=5, hatch_rate=5, wait=False)
     runner.hatching_greenlet.join()
     self.assertEqual(5, len(runner.user_greenlets))
     runner.quit()
Ejemplo n.º 3
0
    def test_stop_event_quit(self):
        class MyUser(User):
            wait_time = constant(1)
            @task
            def my_task(self):
                pass

        test_stop_run = [0]
        environment = Environment(user_classes=[User])
        def on_test_stop(*args, **kwargs):
            test_stop_run[0] += 1
        environment.events.test_stop.add_listener(on_test_stop)

        runner = LocalRunner(environment)
        runner.start(user_count=3, hatch_rate=3, wait=False)
        self.assertEqual(0, test_stop_run[0])
        runner.quit()
        self.assertEqual(1, test_stop_run[0])
Ejemplo n.º 4
0
 def test_cpu_warning(self):
     _monitor_interval = runners.CPU_MONITOR_INTERVAL
     runners.CPU_MONITOR_INTERVAL = 2.0
     try:
         class CpuUser(User):
             wait_time = constant(0.001)
             @task
             def cpu_task(self):
                 for i in range(1000000):
                     _ = 3 / 2
         environment = Environment(user_classes=[CpuUser])
         runner = LocalRunner(environment)
         self.assertFalse(runner.cpu_warning_emitted)
         runner.spawn_users(1, 1, wait=False)
         sleep(2.5)
         runner.quit()
         self.assertTrue(runner.cpu_warning_emitted)
     finally:
         runners.CPU_MONITOR_INTERVAL = _monitor_interval