Exemplo n.º 1
0
def test_failed_over_master_start(app):
    # A master has failed over and restarted, another master has sucessfully advanced
    plugins = setup_plugins(app,
            dcs_lock=False,
            dcs_get_timeline=2,
            pg_get_timeline=1,
            pg_replication_role='master')
    # 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'),
            call.dcs_get_lock_owner('master'),
            call.pg_stop(),
            # compare our timeline to what's in the DCS
            call.pg_get_timeline(),
            call.dcs_get_timeline(),
            # we're on an older timeline, so reset
            call.pg_reset(),
            ]
    # Carry on running afterwards
    assert timeout == 5
Exemplo n.º 2
0
async def test_replica_reaction_to_master_lock_change(app):
    plugins = setup_plugins(app,
            pg_get_timeline=42,
            pg_replication_role='replica')
    assert app.initialize() == None
    plugins.reset_mock()
    # if the lock changes owner to someone else, carry on trucking
    plugins.reset_mock()
    app.master_lock_changed('someone else')
    assert app._plugins.mock_calls ==  [
            call.pg_replication_role(),
            ]
    assert app._master_lock_owner == 'someone else'
    # if the lock is owned by us, er, we stop replication and become the master
    plugins.reset_mock()
    plugins.pg_replication_role.side_effect = ['replica', 'master']
    app.master_lock_changed(app.my_id)
    assert app._plugins.mock_calls ==  [
            call.pg_replication_role(),
            call.pg_stop_replication(),
            call.pg_replication_role(),
            call.pg_get_timeline(),
            call.dcs_set_timeline(42),
            call.dcs_set_state({
                'health_problems': {},
                'replication_role': 'master',
                'host': '127.0.0.1'}),
            ]
    assert app._master_lock_owner == app.my_id
Exemplo n.º 3
0
def test_failed_over_master_start(app):
    # A master has failed over and restarted, another master has sucessfully advanced
    plugins = setup_plugins(app,
                            dcs_lock=False,
                            dcs_get_timeline=2,
                            pg_get_timeline=1,
                            pg_replication_role='master')
    # 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'),
        call.dcs_get_lock_owner('master'),
        call.pg_stop(),
        # compare our timeline to what's in the DCS
        call.pg_get_timeline(),
        call.dcs_get_timeline(),
        # we're on an older timeline, so reset
        call.pg_reset(),
    ]
    # Carry on running afterwards
    assert timeout == 5
Exemplo n.º 4
0
async def test_replica_reaction_to_master_lock_change(app):
    plugins = setup_plugins(app,
                            pg_get_timeline=42,
                            pg_replication_role='replica')
    assert app.initialize() == None
    plugins.reset_mock()
    # if the lock changes owner to someone else, carry on trucking
    plugins.reset_mock()
    app.master_lock_changed('someone else')
    assert plugins.mock_calls == [
        call.pg_replication_role(),
        call.master_lock_changed('someone else')
    ]
    assert app._master_lock_owner == 'someone else'
    # if the lock is owned by us, er, we stop replication and become the master
    plugins.reset_mock()
    plugins.pg_replication_role.side_effect = ['replica', 'master']
    app.master_lock_changed(app.my_id)
    assert plugins.mock_calls == [
        call.pg_replication_role(),
        call.dcs_set_state({
            'replication_role': 'taking-over',
            'willing': None,
            'health_problems': {},
            'host': '127.0.0.1'
        }),
        call.pg_stop_replication(),
        call.pg_replication_role(),
        call.pg_get_timeline(),
        call.dcs_set_timeline(42),
        call.dcs_set_state({
            'health_problems': {},
            'replication_role': 'master',
            'willing': None,
            'host': '127.0.0.1'
        }),
        call.master_lock_changed('42')
    ]
    assert app._master_lock_owner == app.my_id
Exemplo n.º 5
0
async def test_replica_reaction_to_master_lock_change(app):
    plugins = setup_plugins(app,
            pg_get_timeline=42,
            pg_am_i_replica=True)
    assert app.initialize() == None
    plugins.reset_mock()
    # if the lock changes owner to someone else, carry on trucking
    plugins.reset_mock()
    app.master_lock_changed('someone else')
    assert app._plugins.mock_calls ==  [
            call.pg_am_i_replica(),
            ]
    assert app._master_lock_owner == 'someone else'
    # if the lock is owned by us, er, we stop replication and become the master
    plugins.reset_mock()
    app.master_lock_changed(app.my_id)
    print(app._plugins.mock_calls)
    assert app._plugins.mock_calls ==  [
            call.pg_am_i_replica(),
            call.pg_stop_replication(),
            call.pg_get_timeline(),
            call.dcs_set_timeline(42),
            ]
    assert app._master_lock_owner == app.my_id