def test_threads_stop_when_terminated(block_processor):
    # When status is "terminated", the methods running the threads should stop immediately

    chain_monitor = ChainMonitor([Queue(), Queue()], block_processor, bitcoind_feed_params)
    chain_monitor.terminate()

    # If any of the function does not exit immediately, the test will timeout
    chain_monitor.monitor_chain_polling()
    chain_monitor.monitor_chain_zmq()
    chain_monitor.notify_subscribers()
def test_notify_subscribers(block_processor):
    chain_monitor = ChainMonitor(Queue(), Queue(), block_processor,
                                 bitcoind_feed_params)
    # Subscribers are only notified as long as they are awake
    new_block = get_random_value_hex(32)

    # Queues should be empty to start with
    assert chain_monitor.watcher_queue.empty()
    assert chain_monitor.responder_queue.empty()

    chain_monitor.notify_subscribers(new_block)

    assert chain_monitor.watcher_queue.get() == new_block
    assert chain_monitor.responder_queue.get() == new_block