@Test
public void testScaleDownForIdleAgentsDoesNotGoPastInstanceGroupMin() {

    when(configuration.getFlexMinIdle()).thenReturn(0);
    when(configuration.getAgentInstanceRemovableTimeoutMs()).thenReturn(9999999999L);
    AgentInstanceGroup instanceGroup = createPartition("instanceGroup1", InstanceGroupLifecycleState.Active, "r4.16xlarge", 13, 20, 20);
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    List<AgentInstance> agentInstances = CollectionsExt.merge(
            createAgents(18, "instanceGroup1", false),
            createAgents(2, "instanceGroup1", true)
    );
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(agentInstances);
    when(v3JobOperations.getTasks()).thenReturn(emptyList());
    testScheduler.advanceTimeBy(11, TimeUnit.MINUTES);
    ClusterAgentAutoScaler clusterAgentAutoScaler = new ClusterAgentAutoScaler(titusRuntime, configuration,
            agentManagementService, v3JobOperations, schedulingService, testScheduler);
    clusterAgentAutoScaler.doAgentScaling().await();
    verify(agentManagementService, times(5)).updateAgentInstanceAttributes(any(), any());
}