Skip to content

Commit

Permalink
Fix and extend test_last_worker_missing_stops_test - refs locustio#1707
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kane Juncker committed Feb 25, 2021
1 parent ec1d27f commit 6e2b119
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
STATE_SPAWNING,
STATE_RUNNING,
STATE_MISSING,
STATE_STOPPING,
STATE_STOPPED,
)
from locust.stats import RequestStats
Expand Down Expand Up @@ -754,20 +755,45 @@ def test_last_worker_missing_stops_test(self):
master = self.get_runner()
server.mocked_send(Message("client_ready", None, "fake_client1"))
server.mocked_send(Message("client_ready", None, "fake_client2"))
server.mocked_send(Message("client_ready", None, "fake_client3"))

master.start(1, 2)
master.start(3, 3)
server.mocked_send(Message("spawning", None, "fake_client1"))
server.mocked_send(Message("spawning", None, "fake_client2"))
server.mocked_send(Message("spawning", None, "fake_client3"))

sleep(0.2)
server.mocked_send(
Message("heartbeat", {"state": STATE_RUNNING, "current_cpu_usage": 50, "count": 1}, "fake_client1")
)
server.mocked_send(
Message("heartbeat", {"state": STATE_RUNNING, "current_cpu_usage": 50, "count": 1}, "fake_client2")
)
server.mocked_send(
Message("heartbeat", {"state": STATE_RUNNING, "current_cpu_usage": 50, "count": 1}, "fake_client3")
)

sleep(0.3)
server.mocked_send(Message("heartbeat", {"state": STATE_RUNNING, "current_cpu_usage": 50}, "fake_client1"))
sleep(0.2)
self.assertEqual(0, len(master.clients.missing))
self.assertEqual(3, master.worker_count)
self.assertNotIn(
master.state, [STATE_STOPPED, STATE_STOPPING], "Not all workers went missing but test stopped anyway."
)

sleep(0.3)
self.assertEqual(1, len(master.clients.missing))
self.assertNotEqual(STATE_STOPPED, master.state, "Not all workers went missing but test stopped anyway.")
server.mocked_send(
Message("heartbeat", {"state": STATE_RUNNING, "current_cpu_usage": 50, "count": 1}, "fake_client1")
)

sleep(0.3)
sleep(0.4)
self.assertEqual(2, len(master.clients.missing))
self.assertEqual(1, master.worker_count)
self.assertNotIn(
master.state, [STATE_STOPPED, STATE_STOPPING], "Not all workers went missing but test stopped anyway."
)

sleep(0.2)
self.assertEqual(3, len(master.clients.missing))
self.assertEqual(0, master.worker_count)
self.assertEqual(STATE_STOPPED, master.state, "All workers went missing but test didn't stop.")

def test_master_total_stats(self):
Expand Down

0 comments on commit 6e2b119

Please sign in to comment.