diff --git a/pisa/responder.py b/pisa/responder.py index e92a4eb..d0efbb9 100644 --- a/pisa/responder.py +++ b/pisa/responder.py @@ -59,8 +59,8 @@ class Responder: self.tx_job_map = dict() self.unconfirmed_txs = [] self.missed_confirmations = dict() - self.block_queue = None self.asleep = True + self.block_queue = Queue() self.zmq_subscriber = None self.db_manager = db_manager @@ -118,7 +118,6 @@ class Responder: if self.asleep: self.asleep = False - self.block_queue = Queue() zmq_thread = Thread(target=self.do_subscribe) responder = Thread(target=self.do_watch) zmq_thread.start() @@ -172,6 +171,7 @@ class Responder: # Go back to sleep if there are no more jobs self.asleep = True self.zmq_subscriber.terminate = True + self.block_queue = Queue() logger.info("No more pending jobs, going back to sleep") diff --git a/pisa/watcher.py b/pisa/watcher.py index 4eba685..70dc175 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -21,16 +21,15 @@ class Watcher: def __init__(self, db_manager, responder=None, max_appointments=MAX_APPOINTMENTS): self.appointments = dict() self.locator_uuid_map = dict() - self.block_queue = None self.asleep = True + self.block_queue = Queue() self.max_appointments = max_appointments self.zmq_subscriber = None + self.db_manager = db_manager if not isinstance(responder, Responder): self.responder = Responder(db_manager) - self.db_manager = db_manager - if PISA_SECRET_KEY is None: raise ValueError("No signing key provided. Please fix your pisa.conf") else: @@ -67,7 +66,6 @@ class Watcher: if self.asleep: self.asleep = False - self.block_queue = Queue() zmq_thread = Thread(target=self.do_subscribe) watcher = Thread(target=self.do_watch) zmq_thread.start() @@ -146,5 +144,6 @@ class Watcher: # Go back to sleep if there are no more appointments self.asleep = True self.zmq_subscriber.terminate = True + self.block_queue = Queue() logger.info("No more pending appointments, going back to sleep") diff --git a/test/unit/test_responder.py b/test/unit/test_responder.py index ae1e967..02d32ea 100644 --- a/test/unit/test_responder.py +++ b/test/unit/test_responder.py @@ -84,7 +84,7 @@ def test_init_responder(responder): assert type(responder.tx_job_map) is dict and len(responder.tx_job_map) == 0 assert type(responder.unconfirmed_txs) is list and len(responder.unconfirmed_txs) == 0 assert type(responder.missed_confirmations) is dict and len(responder.missed_confirmations) == 0 - assert responder.block_queue is None + assert responder.block_queue.empty() assert responder.asleep is True assert responder.zmq_subscriber is None diff --git a/test/unit/test_watcher.py b/test/unit/test_watcher.py index 1d082c3..fc397f2 100644 --- a/test/unit/test_watcher.py +++ b/test/unit/test_watcher.py @@ -95,7 +95,7 @@ def is_signature_valid(appointment, signature, pk): def test_init(watcher): assert type(watcher.appointments) is dict and len(watcher.appointments) == 0 assert type(watcher.locator_uuid_map) is dict and len(watcher.locator_uuid_map) == 0 - assert watcher.block_queue is None + assert watcher.block_queue.empty() assert watcher.asleep is True assert watcher.max_appointments == MAX_APPOINTMENTS assert watcher.zmq_subscriber is None