コード例 #1
0
ファイル: test_deadman.py プロジェクト: jinty/zgres
async def test_master_start(app):
    plugins = setup_plugins(app,
            dcs_get_database_identifier='1234',
            dcs_lock=True,
            pg_replication_role='master',
            pg_get_database_identifier='1234')
    def start_monitoring():
        app.unhealthy('test_monitor', 'Waiting for first check')
    plugins.start_monitoring.side_effect = start_monitoring
    # sync startup
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # compare our id with the id in the DCS
            call.dcs_get_database_identifier(),
            call.pg_get_database_identifier(),
            # check if I am a replica
            call.pg_replication_role(),
            # no, so check if there is a master
            call.dcs_lock('master'),
            # no master, so sure the DB is running
            call.pg_start(),
            # start monitoring
            call.start_monitoring(),
            call.dcs_watch(
                app.master_lock_changed,
                app._notify_state,
                app._notify_conn_info,
            ),
            call.get_conn_info(),
            # set our first state
            call.dcs_set_state({
                'host': '127.0.0.1',
                'replication_role': 'master',
                'health_problems': {'test_monitor':
                    {'can_be_replica': False, 'reason': 'Waiting for first check'}}})
            ]
    # Carry on running afterwards
    assert timeout == None
    assert app.health_problems == {'test_monitor': {'can_be_replica': False, 'reason': 'Waiting for first check'}}
    # Our test monitor becomes healthy
    plugins.reset_mock()
    app.healthy('test_monitor')
    assert plugins.mock_calls ==  [
            call.dcs_set_state({
                'host': '127.0.0.1',
                'replication_role': 'master',
                'health_problems': {}}),
            call.pg_replication_role(),
            call.dcs_lock('master'),
            call.dcs_set_conn_info({'host': '127.0.0.1'}),
           ]
コード例 #2
0
ファイル: test_deadman.py プロジェクト: ingted/zgres
def test_replica_start(app):
    plugins = setup_plugins(app,
            dcs_get_database_identifier='1234',
            dcs_lock=True,
            pg_am_i_replica=True,
            pg_get_database_identifier='1234')
    app._conn_info['a'] = 'b'
    def start_monitoring():
        app.unhealthy('test_monitor', 'Waiting for first check')
    plugins.start_monitoring.side_effect = start_monitoring
    # sync startup
    timeout = app.initialize()
    assert plugins.mock_calls ==  [
            call.initialize(),
            call.get_my_id(),
            # compare our id with the id in the DCS
            call.dcs_get_database_identifier(),
            call.pg_get_database_identifier(),
            # check if I am a replica
            call.pg_am_i_replica(),
            # not master, so sure the DB is running
            call.pg_start(),
            # start monitoring
            call.start_monitoring(),
            call.dcs_watch(conn_info=None, state=None),
            # setup our connection info
            call.get_conn_info(),
            # set our first state
            call.dcs_set_state({
                'a': 'b',
                'host': '127.0.0.1',
                'health_problems': {'test_monitor':
                    {'can_be_replica': False, 'reason': 'Waiting for first check'}},
                })
            ]
    # Carry on running afterwards
    assert timeout == None
    assert app.health_problems == {'test_monitor': {'can_be_replica': False, 'reason': 'Waiting for first check'}}
    # Our test monitor becomes healthy
    plugins.reset_mock()
    app.healthy('test_monitor')
    assert plugins.mock_calls ==  [
            call.dcs_set_state({'health_problems': {},
                'a': 'b',
                'host': '127.0.0.1',
                }),
            call.pg_am_i_replica(),
            call.dcs_set_conn_info({'a': 'b', 'host': '127.0.0.1'}),
           ]
コード例 #3
0
def test_replica_start(app):
    plugins = setup_plugins(app,
                            dcs_get_database_identifier='1234',
                            dcs_lock=True,
                            pg_replication_role='replica',
                            pg_get_database_identifier='1234')
    app._conn_info['a'] = 'b'

    def start_monitoring():
        app.unhealthy('test_monitor', 'Waiting for first check')

    plugins.start_monitoring.side_effect = start_monitoring
    # sync startup
    timeout = app.initialize()
    assert plugins.mock_calls == [
        call.initialize(),
        call.get_my_id(),
        # compare our id with the id in the DCS
        call.dcs_get_database_identifier(),
        call.pg_get_database_identifier(),
        # check if I am a replica
        call.pg_replication_role(),
        # not master, so sure the DB is running
        call.pg_start(),
        # start monitoring
        call.start_monitoring(),
        call.dcs_watch(
            app.master_lock_changed,
            app._notify_state,
            app._notify_conn_info,
        ),
        # setup our connection info
        call.get_conn_info(),
        # set our first state
        call.dcs_set_state({
            'a': 'b',
            'host': '127.0.0.1',
            'replication_role': 'replica',
            'health_problems': {
                'test_monitor': {
                    'can_be_replica': False,
                    'reason': 'Waiting for first check'
                }
            },
        })
    ]
    # Carry on running afterwards
    assert timeout == None
    assert app.health_problems == {
        'test_monitor': {
            'can_be_replica': False,
            'reason': 'Waiting for first check'
        }
    }
    # Our test monitor becomes healthy
    plugins.reset_mock()
    with patch('time.time') as mock_time:
        app.healthy('test_monitor')
    assert plugins.mock_calls == [
        call.veto_takeover({
            'health_problems': {},
            'a': 'b',
            'replication_role': 'replica',
            'host': '127.0.0.1'
        }),
        call.dcs_set_state({
            'health_problems': {},
            'a': 'b',
            'replication_role': 'replica',
            'host': '127.0.0.1',
            'willing': mock_time(),
        }),
        call.pg_replication_role(),
        call.dcs_set_conn_info({
            'a': 'b',
            'host': '127.0.0.1'
        }),
    ]