def test_get_healthy_marathon_instances_for_short_app_id_considers_none_start_time_unhealthy( ): fake_client = mock.Mock() fake_task = _make_fake_task('/service.instance.foo.bar', started_at=None) mock_result = mock.Mock(alive=True) fake_task.health_check_results = [mock_result] fakes = [fake_task] fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, 'service.instance', ) assert actual == 0
def test_get_healthy_marathon_instances_for_short_app_id_correctly_counts_alive_tasks( ): fake_client = mock.Mock() fakes = [] for i in range(0, 4): fake_task = _make_fake_task('/service.instance.foo%s.bar%s' % (i, i)) mock_result = mock.Mock(alive=i % 2 == 0) fake_task.health_check_results = [mock_result] fakes.append(fake_task) fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, 'service.instance', ) assert actual == 2
def test_get_healthy_marathon_instances_for_short_app_id_correctly_counts_alive_tasks(): fake_client = mock.Mock() fakes = [] for i in range(0, 4): fake_task = mock.Mock() fake_task.app_id = "/service.instance.foo%s.bar%s" % (i, i) mock_result = mock.Mock() mock_result.alive = True if i % 2 == 0 else False fake_task.health_check_results = [mock_result] fakes.append(fake_task) fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, "service.instance" ) assert actual == 2
def test_get_healthy_marathon_instances_for_short_app_id_considers_none_start_time_unhealthy(): fake_client = mock.Mock() fake_task = mock.Mock() fake_task.app_id = "/service.instance.foo.bar" fake_task.started_at = None mock_result = mock.Mock() mock_result.alive = True fake_task.health_check_results = [mock_result] fakes = [fake_task] fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, "service.instance" ) assert actual == 0
def test_get_healthy_marathon_instances_for_short_app_id_considers_new_tasks_not_healthy_yet(): fake_client = mock.Mock() fakes = [] one_minute = timedelta(minutes=1) for i in range(0, 4): fake_task = mock.Mock() fake_task.app_id = "/service.instance.foo%s.bar%s" % (i, i) # when i == 0, produces a task that has just started (not healthy yet) # otherwise produces a task that was started over a minute ago (healthy) fake_task.started_at = datetime.now() - one_minute * i mock_result = mock.Mock() mock_result.alive = True fake_task.health_check_results = [mock_result] fakes.append(fake_task) fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, "service.instance" ) assert actual == 3
def test_get_healthy_marathon_instances_for_short_app_id_considers_new_tasks_not_healthy_yet(): fake_client = mock.Mock() fakes = [] one_minute = timedelta(minutes=1) for i in range(0, 4): fake_task = mock.Mock() fake_task.app_id = '/service.instance.foo%s.bar%s' % (i, i) # when i == 0, produces a task that has just started (not healthy yet) # otherwise produces a task that was started over a minute ago (healthy) fake_task.started_at = datetime.now() - one_minute * i mock_result = mock.Mock() mock_result.alive = True fake_task.health_check_results = [mock_result] fakes.append(fake_task) fake_client.list_tasks.return_value = fakes actual = check_marathon_services_replication.get_healthy_marathon_instances_for_short_app_id( fake_client, 'service.instance', ) assert actual == 3