Skip to content

Commit

Permalink
add test case for step load
Browse files Browse the repository at this point in the history
  • Loading branch information
delulu committed Nov 4, 2019
1 parent 7a4f6b2 commit 5150d30
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self):
self.heartbeat_liveness = 3
self.heartbeat_interval = 0.01
self.stop_timeout = None
self.step_load = True

def reset_stats(self):
pass
Expand Down Expand Up @@ -411,6 +412,25 @@ class MyTestLocust(Locust):

self.assertEqual(2, num_clients, "Total number of locusts that would have been spawned is not 2")

def test_spawn_locusts_in_stepload_mode(self):
class MyTestLocust(Locust):
pass

with mock.patch("locust.rpc.rpc.Server", mocked_rpc_server()) as server:
master = MasterLocustRunner(MyTestLocust, self.options)
for i in range(5):
server.mocked_send(Message("client_ready", None, "fake_client%i" % i))

master.start_stepload(2, 1, 1, 3)
sleep(1)
self.assertEqual(5, len(server.outbox))

num_clients = 0
for _, msg in server.outbox:
num_clients += Message.unserialize(msg).data["num_clients"]

self.assertEqual(1, num_clients, "Total number of locusts that would have been spawned is not 1")

def test_exception_in_task(self):
class HeyAnException(Exception):
pass
Expand Down

0 comments on commit 5150d30

Please sign in to comment.