code
stringlengths
3
6.57k
MyTestLocust(Locust)
mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()
MasterLocustRunner(MyTestLocust, self.options)
server.mocked_send(Message("client_ready", None, "fake_client")
master.stats.get("/", "GET")
log(100, 23455)
master.stats.get("/", "GET")
log(800, 23455)
master.stats.get("/", "GET")
log(700, 23455)
events.report_to_master.fire(client_id="fake_client", data=data)
master.stats.clear_all()
server.mocked_send(Message("stats", data, "fake_client")
master.stats.get("/", "GET")
self.assertEqual(700, s.median_response_time)
test_master_total_stats(self)
MyTestLocust(Locust)
mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()
MasterLocustRunner(MyTestLocust, self.options)
server.mocked_send(Message("client_ready", None, "fake_client")
RequestStats()
stats.log_request("GET", "/1", 100, 3546)
stats.log_request("GET", "/1", 800, 56743)
RequestStats()
stats2.log_request("GET", "/2", 700, 2201)
stats.serialize_stats()
stats.total.serialize()
stats.serialize_errors()
stats2.serialize_stats()
stats2.total.serialize()
stats2.serialize_errors()
self.assertEqual(700, master.stats.total.median_response_time)
test_master_current_response_times(self)
MyTestLocust(Locust)
mock.patch("time.time")
global_stats.reset_all()
mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()
MasterLocustRunner(MyTestLocust, self.options)
server.mocked_send(Message("client_ready", None, "fake_client")
RequestStats()
stats.log_request("GET", "/1", 100, 3546)
stats.log_request("GET", "/1", 800, 56743)
stats.serialize_stats()
stats.total.get_stripped_report()
stats.serialize_errors()
RequestStats()
stats2.log_request("GET", "/2", 400, 2201)
stats2.serialize_stats()
stats2.total.get_stripped_report()
stats2.serialize_errors()
self.assertEqual(400, master.stats.total.get_current_response_time_percentile(0.5)
self.assertEqual(800, master.stats.total.get_current_response_time_percentile(0.95)
stats.log_request("GET", "/1", 20, 1)
stats.log_request("GET", "/1", 30, 1)
stats.log_request("GET", "/1", 3000, 1)
stats.serialize_stats()
stats.total.get_stripped_report()
stats.serialize_errors()
self.assertEqual(30, master.stats.total.get_current_response_time_percentile(0.5)
self.assertEqual(3000, master.stats.total.get_current_response_time_percentile(0.95)
test_spawn_zero_locusts(self)
MyTaskSet(TaskSet)
my_task(self)
MyTestLocust(Locust)
LocalLocustRunner([MyTestLocust], self.options)
gevent.Timeout(2.0)
timeout.start()
runner.start_hatching(0, 1, wait=True)
runner.greenlet.join()
self.fail("Got Timeout exception. A locust seems to have been spawned, even though 0 was specified.")
timeout.cancel()
test_spawn_uneven_locusts(self)
MyTestLocust(Locust)
mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()
MasterLocustRunner(MyTestLocust, self.options)
range(5)
server.mocked_send(Message("client_ready", None, "fake_client%i" % i)
master.start_hatching(7, 7)
self.assertEqual(5, len(server.outbox)
Message.unserialize(msg)
self.assertEqual(7, num_clients, "Total number of locusts that would have been spawned is not 7")
test_spawn_fewer_locusts_than_slaves(self)
MyTestLocust(Locust)
mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()
MasterLocustRunner(MyTestLocust, self.options)
range(5)
server.mocked_send(Message("client_ready", None, "fake_client%i" % i)
master.start_hatching(2, 2)
self.assertEqual(5, len(server.outbox)
Message.unserialize(msg)
self.assertEqual(2, num_clients, "Total number of locusts that would have been spawned is not 2")
test_exception_in_task(self)
HeyAnException(Exception)
MyLocust(Locust)
task_set(TaskSet)
will_error(self)
HeyAnException(":(")
LocalLocustRunner([MyLocust], self.options)
MyLocust()
self.assertRaises(HeyAnException, l.run)