def test_redis_lock_update(
    test_client,
    pg_docker_fixture,
    rabbitmq_docker_fixture,
    broker_connection,
    mq_handler,
):
    xml_feed = '<?xml version="1.0" encoding="UTF-8"?><something></something>'
    logger = logging.getLogger(
        "kirin.queue_workers.siri_et_xml_tn.siri_et_xml_tn_worker")
    with patch.object(logger, "debug") as mock_debug:
        with SiriEtXmlTnWorkerTest(test_client, rabbitmq_docker_fixture.url,
                                   broker_connection, pg_docker_fixture):
            # Check that SiriEtXmlTnWorker is creating the queue
            wait_until(lambda: is_queue_created(broker_connection,
                                                SIRI_ET_XML_TN_QUEUE_NAME))

            time.sleep((WORKER_REDIS_TIMEOUT_LOCK.total_seconds() // 5) + 1)
            mq_handler.publish(xml_feed, SIRI_ET_XML_TN_CONTRIBUTOR_ID)
            wait_until(lambda: RealTimeUpdate.query.count() == 1)
            # Check lock refreshed
            mock_debug.assert_any_call(
                "lock {%s} updated",
                make_kirin_lock_name("{}_worker".format(
                    ConnectorType.siri_et_xml_tn.value)))
예제 #2
0
 def __enter__(self):
     # Launch a PivWorker
     self.thread = threading.Thread(target=launch_piv_worker,
                                    args=(self.pg_docker_fixture, ))
     self.thread.start()
     wait_until(lambda: self.thread.is_alive())
     # Check that PivWorker is ready (a good hint is when queue is created)
     wait_until(
         lambda: is_queue_created(self.broker_connection, PIV_QUEUE_NAME))
 def __enter__(self):
     # Launch a SiriEtXmlTnWorker
     self.thread = threading.Thread(target=launch_siri_et_xml_tn_worker,
                                    args=(self.pg_docker_fixture, ))
     self.thread.start()
     wait_until(lambda: self.thread.is_alive())
     # Check that SiriEtXmlTnWorker is ready (a good hint is when queue is created)
     wait_until(lambda: is_queue_created(self.broker_connection,
                                         SIRI_ET_XML_TN_QUEUE_NAME))
예제 #4
0
def test_mq_message_received_and_stored(test_client, pg_docker_fixture,
                                        rabbitmq_docker_fixture,
                                        broker_connection, mq_handler):
    with PivWorkerTest(test_client, rabbitmq_docker_fixture.url,
                       broker_connection, pg_docker_fixture):
        # Check that PivWorker is creating the queue
        wait_until(lambda: is_queue_created(broker_connection, PIV_QUEUE_NAME))

        # Check that MQ message is received and stored in DB
        mq_handler.publish('{"key": "Some valid JSON"}', PIV_CONTRIBUTOR_ID)
        wait_until(lambda: RealTimeUpdate.query.count() == 1)
def test_mq_message_received_and_stored(test_client, pg_docker_fixture,
                                        rabbitmq_docker_fixture,
                                        broker_connection, mq_handler):
    xml_feed = '<?xml version="1.0" encoding="UTF-8"?><something></something>'
    with SiriEtXmlTnWorkerTest(test_client, rabbitmq_docker_fixture.url,
                               broker_connection, pg_docker_fixture):
        # Check that SiriEtXmlTnWorker is creating the queue
        wait_until(lambda: is_queue_created(broker_connection,
                                            SIRI_ET_XML_TN_QUEUE_NAME))

        # Check that MQ message is received and stored in DB
        mq_handler.publish(xml_feed, SIRI_ET_XML_TN_CONTRIBUTOR_ID)
        wait_until(lambda: RealTimeUpdate.query.count() == 1)
예제 #6
0
def test_redis_lock_update(
    test_client,
    pg_docker_fixture,
    rabbitmq_docker_fixture,
    broker_connection,
    mq_handler,
):
    logger = logging.getLogger("kirin.queue_workers.piv.piv_worker")
    with patch.object(logger, "debug") as mock_debug:
        with PivWorkerTest(test_client, rabbitmq_docker_fixture.url,
                           broker_connection, pg_docker_fixture):
            # Check that PivWorker is creating the queue
            wait_until(
                lambda: is_queue_created(broker_connection, PIV_QUEUE_NAME))

            time.sleep((WORKER_REDIS_TIMEOUT_LOCK.total_seconds() // 5) + 1)
            mq_handler.publish('{"key": "Some valid JSON"}',
                               PIV_CONTRIBUTOR_ID)
            wait_until(lambda: RealTimeUpdate.query.count() == 1)
            # Check lock refreshed
            mock_debug.assert_any_call(
                "lock {%s} updated",
                make_kirin_lock_name("{}_worker".format(
                    ConnectorType.piv.value)))
예제 #7
0
 def __exit__(self, type, value, traceback):
     # Remove the contributor
     self.test_client.delete("/contributors/{}".format(PIV_CONTRIBUTOR_ID))
     # PivWorker should die eventually when no PIV contributors is available
     wait_until(lambda: not self.thread.is_alive())
 def __exit__(self, type, value, traceback):
     # Remove the contributor
     self.test_client.delete(
         "/contributors/{}".format(SIRI_ET_XML_TN_CONTRIBUTOR_DB_ID))
     # SiriEtXmlTnWorker should die eventually when no SIRI_ET_XML_TN contributors is available
     wait_until(lambda: not self.thread.is_alive())