From 12d925c739a097da6b49af12b56207cc2462bb5d Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Sat, 28 Jan 2017 14:23:40 +0100 Subject: [PATCH] shutdown without start will RuntimeError --- coolamqp/clustering/cluster.py | 8 +++++++- tests/test_clustering/test_things.py | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/coolamqp/clustering/cluster.py b/coolamqp/clustering/cluster.py index 81c4629..497b938 100644 --- a/coolamqp/clustering/cluster.py +++ b/coolamqp/clustering/cluster.py @@ -50,7 +50,6 @@ class Cluster(object): self.node, = nodes - def declare(self, obj, persistent=False): """ Declare a Queue/Exchange @@ -175,7 +174,14 @@ class Cluster(object): """ Terminate all connections, release resources - finish the job. :param wait: block until this is done + :raise RuntimeError: if called without start() being called first """ + + try: + self.listener + except AttributeError: + raise RuntimeError(u'shutdown without start') + logger.info('Commencing shutdown') self.listener.terminate() diff --git a/tests/test_clustering/test_things.py b/tests/test_clustering/test_things.py index daef9f2..fd35acf 100644 --- a/tests/test_clustering/test_things.py +++ b/tests/test_clustering/test_things.py @@ -19,3 +19,8 @@ class TestConnecting(unittest.TestCase): c.start(wait=True) self.assertRaises(RuntimeError, lambda: c.start()) c.shutdown(wait=True) + + + def test_shutdown_without_start(self): + c = Cluster([NODE]) + self.assertRaises(RuntimeError, lambda: c.shutdown()) -- GitLab