@pytest.mark.parametrize('num_in_progress_runs', [0, 1, 3, 4, 5])
def test_get_queued_runs_max_runs(instance, num_in_progress_runs, grpc_server_registry):
    max_runs = 4
    in_progress_run_ids = ['in_progress-run-{}'.format(i) for i in range(num_in_progress_runs)]
    for (i, run_id) in enumerate(in_progress_run_ids):
        status = IN_PROGRESS_RUN_STATUSES[(i % len(IN_PROGRESS_RUN_STATUSES))]
        create_run(instance, run_id=run_id, status=status)
    queued_run_ids = ['queued-run-{}'.format(i) for i in range((max_runs + 1))]
    for run_id in queued_run_ids:
        create_run(instance, run_id=run_id, status=PipelineRunStatus.QUEUED)
    coordinator = QueuedRunCoordinatorDaemon(interval_seconds=5, max_concurrent_runs=max_runs)
    list(coordinator.run_iteration(instance, grpc_server_registry))
    assert (len(instance.run_launcher.queue()) == max(0, (max_runs - num_in_progress_runs)))
@pytest.mark.parametrize('num_in_progress_runs', [0, 1, 3, 4, 5])
def test_get_queued_runs_max_runs(instance, num_in_progress_runs, grpc_server_registry):
    max_runs = 4
    in_progress_run_ids = ['in_progress-run-{}'.format(i) for i in range(num_in_progress_runs)]
    for (i, run_id) in enumerate(in_progress_run_ids):
        status = IN_PROGRESS_RUN_STATUSES[(i % len(IN_PROGRESS_RUN_STATUSES))]
        create_run(instance, run_id=run_id, status=status)
    queued_run_ids = ['queued-run-{}'.format(i) for i in range((max_runs + 1))]
    for run_id in queued_run_ids:
        create_run(instance, run_id=run_id, status=PipelineRunStatus.QUEUED)
    coordinator = QueuedRunCoordinatorDaemon(interval_seconds=5, max_concurrent_runs=max_runs)
    list(coordinator.run_iteration(instance, grpc_server_registry))
    assert (len(instance.run_launcher.queue()) == max(0, (max_runs - num_in_progress_runs)))