@Test
public void testFailedRetriedRequestsAreConsideredInFlight() throws Exception {

  String agentUrl = "http://agent2";
  startAgent(agentUrl, TEST_LB_GROUP);
  requestManager.enqueueRequest(createBaseRequest("request1", "service1", ImmutableSet.of(TEST_LB_GROUP)).build());
  requestWorker.run(); // move from pending -> send apply
  requestWorker.run(); // actually send
  Assertions.assertEquals(1, testAgentManager.getRecentBatches().get(agentUrl).size());
  testAgentManager.completeRequestWithFailure(agentUrl, agentUrl, "request1", AgentRequestType.APPLY);
  requestWorker.run(); // see the failed response, move to retry
  Assertions.assertEquals(InternalRequestStates.SEND_APPLY_REQUESTS, requestManager.getRequestState("request1").get());

  // second request for same service should not send a request batch
  requestManager.enqueueRequest(createBaseRequest("request2", "service1", ImmutableSet.of(TEST_LB_GROUP)).build());
  Assertions.assertEquals(1, testAgentManager.getRecentBatches().get(agentUrl).size());
  Assertions.assertEquals("request1", testAgentManager.getRecentBatches().get(agentUrl).get(0).getRequestId());
}