Skip to content

Commit

Permalink
Decrease run time for test that tests master node's ability to recove…
Browse files Browse the repository at this point in the history
…r from network problems.

Remove test for unhandled exceptions in MasterLocustRunner.client_listener. It was causing stack traces to be printed and if that happens (unhandled exception in client_listener) we're fucked anyways so there's really no need to test for it.
  • Loading branch information
heyman committed Apr 5, 2020
1 parent 979f582 commit 2ac0a84
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from locust.wait_time import between, constant

NETWORK_BROKEN = "network broken"
UNHANDLED_EXCEPTION = "unhandled exception"

def mocked_rpc():
class MockedRpcServerClient(object):
Expand All @@ -38,8 +37,6 @@ def recv(self):
msg = Message.unserialize(results)
if msg.data == NETWORK_BROKEN:
raise RPCError()
if msg.data == UNHANDLED_EXCEPTION:
raise HeyAnException()
return msg

def send(self, message):
Expand All @@ -53,8 +50,6 @@ def recv_from_client(self):
msg = Message.unserialize(results)
if msg.data == NETWORK_BROKEN:
raise RPCError()
if msg.data == UNHANDLED_EXCEPTION:
raise HeyAnException()
return msg.node_id, msg

def close(self):
Expand Down Expand Up @@ -699,17 +694,17 @@ class MyLocust(Locust):

def test_master_reset_connection(self):
""" Test that connection will be reset when network issues found """
with mock.patch("locust.rpc.rpc.Server", mocked_rpc()) as server:
master = self.get_runner()
server.mocked_send(Message("client_ready", NETWORK_BROKEN, "fake_client"))
sleep(3)
assert master.connection_broken == True
server.mocked_send(Message("client_ready", None, "fake_client"))
sleep(3)
assert master.connection_broken == False
server.mocked_send(Message("client_ready", UNHANDLED_EXCEPTION, "fake_client"))
sleep(3)
assert master.connection_broken == False
with mock.patch("locust.runners.FALLBACK_INTERVAL", new=0.1):
with mock.patch("locust.rpc.rpc.Server", mocked_rpc()) as server:
master = self.get_runner()
self.assertEqual(0, len(master.clients))
server.mocked_send(Message("client_ready", NETWORK_BROKEN, "fake_client"))
self.assertTrue(master.connection_broken)
server.mocked_send(Message("client_ready", None, "fake_client"))
sleep(0.2)
self.assertFalse(master.connection_broken)
self.assertEqual(1, len(master.clients))
master.quit()

class TestWorkerLocustRunner(LocustTestCase):
def setUp(self):
Expand Down

0 comments on commit 2ac0a84

Please sign in to comment.