From 0dfcd3557a5fecc4ead47e2be2dc333a4719969e Mon Sep 17 00:00:00 2001 From: Oliver Palmer Date: Thu, 5 Mar 2015 00:11:39 -0500 Subject: [PATCH] test for should_reannounce(), restarting tests for TestReannounce() --- tests/test_agent/test_service.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/test_agent/test_service.py b/tests/test_agent/test_service.py index f73c36e5..e1b17fe6 100644 --- a/tests/test_agent/test_service.py +++ b/tests/test_agent/test_service.py @@ -827,3 +827,42 @@ def test_timeout(self): stop_lock_acquire.assert_called_once() stop_lock_release.assert_called_once() + +class TestShouldReannounce(TestCase): + POP_CONFIG_KEYS = [ + "agent_master_reannounce", "last_master_contact" + ] + + def test_should_reannounce_locked(self): + agent = Agent() + agent.reannouce_lock.acquire() + self.assertFalse(agent.should_reannounce()) + + def test_should_reannounce_shutting_down(self): + agent = Agent() + agent.shutting_down = True + self.assertFalse(agent.should_reannounce()) + + def test_should_reannounce_master_contacted(self): + config["last_master_contact"] = datetime.utcnow() - timedelta(seconds=5) + config["agent_master_reannounce"] = 3 + agent = Agent() + self.assertTrue(agent.should_reannounce()) + + +class TestReannounce(TestCase): + @inlineCallbacks + def test_should_not_reannounce(self): + agent = Agent() + + with nested( + patch.object(agent, "should_reannounce", return_value=False), + patch.object(agent.reannouce_lock, "acquire"), + patch.object(agent.reannouce_lock, "release"), + ) as (should_reannounce, acquire_lock, release_lock): + result = yield agent.reannounce() + + self.assertIsNone(result) + acquire_lock.assert_called_once() + release_lock.assert_called_once() +