diff --git a/coolamqp/clustering/cluster.py b/coolamqp/clustering/cluster.py index b45ec09df8478d331c003bc1816953276a757825..81c4629f47462266f42871dcaa047ec711b2e508 100644 --- a/coolamqp/clustering/cluster.py +++ b/coolamqp/clustering/cluster.py @@ -133,7 +133,16 @@ class Cluster(object): It is not safe to fork after this. :param wait: block until connection is ready + :raise RuntimeError: called more than once """ + + try: + self.listener + except AttributeError: + pass + else: + raise RuntimeError(u'This was already called!') + self.listener = ListenerThread() self.attache_group = AttacheGroup() diff --git a/tests/test_clustering/test_things.py b/tests/test_clustering/test_things.py new file mode 100644 index 0000000000000000000000000000000000000000..daef9f23b5918fad9c62dfda276fe322b700d09c --- /dev/null +++ b/tests/test_clustering/test_things.py @@ -0,0 +1,21 @@ +# coding=UTF-8 + +from __future__ import print_function, absolute_import, division +import six +import unittest +import time, logging, threading, monotonic +from coolamqp.objects import Message, MessageProperties, NodeDefinition, Queue, ReceivedMessage, Exchange +from coolamqp.clustering import Cluster, MessageReceived, NothingMuch + +import time +NODE = NodeDefinition('127.0.0.1', 'guest', 'guest', heartbeat=20) +logging.basicConfig(level=logging.DEBUG) + + +class TestConnecting(unittest.TestCase): + + def test_start_called_multiple_times(self): + c = Cluster([NODE]) + c.start(wait=True) + self.assertRaises(RuntimeError, lambda: c.start()) + c.shutdown(wait=True)