Example #1
0
    def test_fails_to_create_session_id_when_unhealthy(self):
        consul_ha = ConsulHa("unhealthy-secondary", 0)
        state_handler = StateHandler({})
        consul_ha.state_handler = state_handler

        self.assertFalse(consul_ha.run_cycle())
        pass
Example #2
0
    def test_fails_to_create_session_id_when_unhealthy(self):
        consul_ha = ConsulHa("unhealthy-secondary", 0)
        state_handler = StateHandler({})
        consul_ha.state_handler = state_handler

        self.assertFalse(consul_ha.run_cycle())
        pass
Example #3
0
    def test_obtain_lock_as_primary(self):
        consul_ha = ConsulHa("healthy-primary", 0)
        state_handler = StateHandler({'is_leader': True})
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        pass
Example #4
0
    def test_obtain_lock_as_primary(self):
        consul_ha = ConsulHa("healthy-primary", 0)
        state_handler = StateHandler({'is_leader': True})
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        pass
Example #5
0
    def test_obtain_lock_as_secondary_and_not_most_healthy(self):
        consul_ha = ConsulHa("healthy-secondary", 0)
        state_handler = StateHandler({'is_leader': False, 'passes_health_requirements': False})
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        self.assertTrue(state_handler.called_passes_health_requirements)
        pass
Example #6
0
    def test_lose_lock_as_primary_with_new_primary(self):
        grab_session_for_service('healthy-primary')

        consul_ha = ConsulHa("healthy-primary", 0)
        state_handler = StateHandler({'is_leader': True, 'demote': True})
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        self.assertTrue(state_handler.called_demote)

        pass
Example #7
0
    def test_obtain_lock_as_secondary_and_not_most_healthy(self):
        consul_ha = ConsulHa("healthy-secondary", 0)
        state_handler = StateHandler({
            'is_leader': False,
            'passes_health_requirements': False
        })
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        self.assertTrue(state_handler.called_passes_health_requirements)
        pass
Example #8
0
    def test_lose_lock_as_primary_with_new_primary(self):
        grab_session_for_service('healthy-primary')

        consul_ha = ConsulHa("healthy-primary", 0)
        state_handler = StateHandler({'is_leader': True, 'demote': True})
        consul_ha.state_handler = state_handler

        consul_ha.run_cycle()

        self.assertTrue(state_handler.called_is_leader)
        self.assertTrue(state_handler.called_demote)

        pass