Beispiel #1
0
def test_main_loop(db):
    config = {
        "remote_conns": {
            "test1db": db.connection_string("testuser"),
            "test2db": db.connection_string("otheruser"),
        },
    }
    cluster_state = {}
    observer_state = {}

    def create_alert_file(arg):
        raise Exception(arg)

    cluster_monitor_check_queue = Queue()
    failover_decision_queue = Queue()

    cm = ClusterMonitor(
        config=config,
        cluster_state=cluster_state,
        observer_state=observer_state,
        create_alert_file=create_alert_file,
        cluster_monitor_check_queue=cluster_monitor_check_queue,
        failover_decision_queue=failover_decision_queue,
        stats=statsd.StatsClient(host=None),
    )
    cm.main_monitoring_loop(requested_check=True)

    assert len(cm.cluster_state) == 2
    assert "test1db" in cm.cluster_state
    assert "test2db" in cm.cluster_state

    assert failover_decision_queue.get(timeout=5) == "Completed requested monitoring loop"
def test_main_loop(db):
    config = {
        "remote_conns": {
            "test1db": db.connection_string("testuser"),
            "test2db": db.connection_string("otheruser"),
        },
    }
    cluster_state = {}
    observer_state = {}

    def create_alert_file(arg):
        raise Exception(arg)

    trigger_check_queue = Queue()
    trigger_check_queue.put(
        "test entry so we don't wait five seconds to get one")

    cm = ClusterMonitor(
        config=config,
        cluster_state=cluster_state,
        observer_state=observer_state,
        create_alert_file=create_alert_file,
        trigger_check_queue=trigger_check_queue,
        stats=statsd.StatsClient(host=None),
    )
    cm.main_monitoring_loop()

    assert len(cm.cluster_state) == 2
    assert "test1db" in cm.cluster_state
    assert "test2db" in cm.cluster_state
def test_main_loop(db):
    config = {
        "remote_conns": {
            "test1db": db.connection_string("testuser"),
            "test2db": db.connection_string("otheruser"),
        },
        "observers": {
            "local": "URL"
        },
        "poll_observers_on_warning_only": True
    }
    cluster_state = {}
    observer_state = {}

    def create_alert_file(arg):
        raise Exception(arg)

    cluster_monitor_check_queue = Queue()
    failover_decision_queue = Queue()

    cm = ClusterMonitor(
        config=config,
        cluster_state=cluster_state,
        observer_state=observer_state,
        create_alert_file=create_alert_file,
        cluster_monitor_check_queue=cluster_monitor_check_queue,
        failover_decision_queue=failover_decision_queue,
        stats=statsd.StatsClient(host=None),
        is_replication_lag_over_warning_limit=lambda: False)
    cm.main_monitoring_loop(requested_check=True)

    assert len(cm.cluster_state) == 2
    assert "test1db" in cm.cluster_state
    assert "test2db" in cm.cluster_state

    assert failover_decision_queue.get(
        timeout=5) == "Completed requested monitoring loop"

    with patch.object(cm, "fetch_observer_state") as fetch_observer_state:
        cm.main_monitoring_loop(requested_check=True)
        fetch_observer_state.assert_not_called()

    with patch.object(cm, "fetch_observer_state") as fetch_observer_state:
        with patch.object(cm, "is_replication_lag_over_warning_limit",
                          lambda: True):
            cm.main_monitoring_loop(requested_check=True)
            fetch_observer_state.assert_called_once_with("local", "URL")

    with patch.object(cm, "fetch_observer_state") as fetch_observer_state:
        with patch.dict(cm.config, {"poll_observers_on_warning_only": False}):
            cm.main_monitoring_loop(requested_check=True)
            fetch_observer_state.assert_called_once_with("local", "URL")