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
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
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
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
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