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
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.º 3
0
def test_replica_bootstrap_fails_sanity_test(app):
    plugins = setup_plugins(app,
            pg_am_i_replica=False,
            dcs_get_database_identifier='1234',
            pg_get_database_identifier='42')
    timeout = app.initialize()
    assert app._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(),
            # make sure postgresql is stopped
            call.pg_stop(),
            # postgresql restore
            call.pg_restore(),
            call.pg_setup_replication(),
            call.pg_am_i_replica(),
            call.pg_reset(),
            ]
    # shut down after 5 seconds to try again
    assert timeout == 5
Exemplo n.º 4
0
def test_replica_bootstrap_fails_sanity_test(app):
    plugins = setup_plugins(app,
                            pg_replication_role='master',
                            dcs_get_database_identifier='1234',
                            pg_get_database_identifier='42')
    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(),
        # make sure postgresql is stopped
        call.pg_stop(),
        # postgresql restore
        call.pg_initdb(),
        call.pg_restore(),
        call.pg_setup_replication(None),
        call.pg_get_database_identifier(),
        call.pg_replication_role(),
        call.pg_reset(),
    ]
    # shut down after 5 seconds to try again
    assert timeout == 5