From 2a26d386b26235cfee773af52b8be3f0700deaf5 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Sat, 28 Jan 2017 13:02:56 +0100 Subject: [PATCH] start() will throw RuntimeError if called more than once --- coolamqp/clustering/cluster.py | 9 +++++++++ tests/test_clustering/test_things.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/test_clustering/test_things.py diff --git a/coolamqp/clustering/cluster.py b/coolamqp/clustering/cluster.py index b45ec09..81c4629 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 0000000..daef9f2 --- /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) -- GitLab