@Test
public void testScaleUpForTasksPastSlo() {

    when(configuration.getFlexMinIdle()).thenReturn(0);
    when(configuration.getFlexScaleUpCoolDownMs()).thenReturn(72000000L);
    when(configuration.getFlexTaskSloMs()).thenReturn(3600000L);
    AgentInstanceGroup instanceGroup = createPartition("instanceGroup1", InstanceGroupLifecycleState.Active, "r4.16xlarge", 0, 0, 10);
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(Collections.emptyList());
    when(agentManagementService.scaleUp(eq("instanceGroup1"), anyInt())).thenReturn(Completable.complete());
    testScheduler.advanceTimeBy(6, TimeUnit.MINUTES);
    ClusterAgentAutoScaler clusterAgentAutoScaler = new ClusterAgentAutoScaler(titusRuntime, configuration,
            agentManagementService, v3JobOperations, schedulingService, testScheduler);
    clusterAgentAutoScaler.doAgentScaling().await();
    Job job = createJob();
    when(v3JobOperations.getJobs()).thenReturn(Collections.singletonList(job));
    List<Task> tasks = createTasks(10, "jobId");
    when(v3JobOperations.getTasks()).thenReturn(tasks);
    Map<FailureKind, Map<StubTaskRequest, List<TaskPlacementFailure>>> taskPlacementFailures = createTaskPlacementFailures(ImmutableMap.of(
            AllAgentsFull, 10
    ), Tier.Flex);
    doReturn(taskPlacementFailures).when(schedulingService).getLastTaskPlacementFailures();
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(Collections.emptyList());
    when(agentManagementService.scaleUp(eq("instanceGroup1"), anyInt())).thenReturn(Completable.complete());
    testScheduler.advanceTimeBy(1, TimeUnit.HOURS);
    clusterAgentAutoScaler.doAgentScaling().await();
    verify(agentManagementService).scaleUp("instanceGroup1", 10);
}