@Test
public void testScaleDownForIdleAgents() {

    when(configuration.getFlexMinIdle()).thenReturn(0);
    when(configuration.getFlexMaxIdle()).thenReturn(0);
    AgentInstanceGroup instanceGroup = createPartition("instanceGroup1", InstanceGroupLifecycleState.Active, "r4.16xlarge", 0, 20, 20);
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    List<AgentInstance> agentInstances = createAgents(20, "instanceGroup1", false);
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(agentInstances);
    List<Task> tasks = createTasks(17, "jobId");
    for (int i = 0; i < tasks.size(); i++) {
        Task task = tasks.get(i);
        when(task.getTaskContext()).thenReturn(singletonMap(TaskAttributes.TASK_ATTRIBUTES_AGENT_INSTANCE_ID, "instanceGroup1" + i));
    }
    when(v3JobOperations.getTasks()).thenReturn(tasks);
    testScheduler.advanceTimeBy(11, TimeUnit.MINUTES);
    ClusterAgentAutoScaler clusterAgentAutoScaler = new ClusterAgentAutoScaler(titusRuntime, configuration,
            agentManagementService, v3JobOperations, schedulingService, testScheduler);
    clusterAgentAutoScaler.doAgentScaling().await();
    verify(agentManagementService, times(3)).updateAgentInstanceAttributes(any(), any());
}