@Test
public void discardUnregisteredAgents() {

    TestSBuildAgent agentWithCloudAndInstanceIds = new TestSBuildAgent().
            environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString()).
            environmentVariable(DockerCloudUtils.ENV_INSTANCE_ID, TestUtils.TEST_UUID_2.toString());
    TestSBuildAgent agentWithCloudIdOnly = new TestSBuildAgent().
            environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString());
    TestSBuildAgent agentWithCloudAndInstanceIdsNotRemovable = new TestSBuildAgent().
            environmentVariable(DockerCloudUtils.ENV_CLIENT_ID, TestUtils.TEST_UUID.toString()).
            environmentVariable(DockerCloudUtils.ENV_INSTANCE_ID, TestUtils.TEST_UUID_2.toString()).
            removable(false);
    TestSBuildAgent otherAgent = new TestSBuildAgent();
    buildServer.getTestBuildAgentManager().
            unregisteredAgent(agentWithCloudAndInstanceIds).
            unregisteredAgent(agentWithCloudIdOnly).
            unregisteredAgent(agentWithCloudAndInstanceIdsNotRemovable).
            unregisteredAgent(otherAgent);
    DefaultDockerCloudClient client = createClient();
    waitUntil(() -> buildServer.getBuildAgentManager().getUnregisteredAgents().size() == 2);
    List<TestSBuildAgent> unregisteredAgents = buildServer.getBuildAgentManager().getUnregisteredAgents();
    assertThat(unregisteredAgents).containsOnly(agentWithCloudAndInstanceIdsNotRemovable, otherAgent);
    assertThat(client.getErrorInfo()).isNull();
}