Program: 160294
Project: 160294
Buggy source:
/** 
 * Make sure that if a continuous push gets an error pushing a doc, it will keep retrying it rather than giving up right away.
 * @throws Exception
 */
public void testContinuousPushRetryBehavior() throws Exception {
  RemoteRequestRetry.RETRY_DELAY_MS=5;
  ReplicationInternal.RETRY_DELAY_SECONDS=1;
  ReplicationInternal.MAX_RETRIES=3;
  MockDispatcher dispatcher=new MockDispatcher();
  MockWebServer server=MockHelper.getMockWebServer(dispatcher);
  dispatcher.setServerType(MockDispatcher.ServerType.SYNC_GW);
  MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
  mockCheckpointPut.setSticky(true);
  mockCheckpointPut.setDelayMs(500);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
  MockRevsDiff mockRevsDiff=new MockRevsDiff();
  mockRevsDiff.setSticky(true);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_REVS_DIFF,mockRevsDiff);
  MockResponse mockResponse=new MockResponse().setResponseCode(503);
  WrappedSmartMockResponse mockBulkDocs=new WrappedSmartMockResponse(mockResponse,false);
  mockBulkDocs.setSticky(true);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_BULK_DOCS,mockBulkDocs);
  server.play();
  Replication replication=database.createPushReplication(server.getUrl("String_Node_Str"));
  replication.setContinuous(true);
  CountDownLatch replicationIdle=new CountDownLatch(1);
  ReplicationIdleObserver idleObserver=new ReplicationIdleObserver(replicationIdle);
  replication.addChangeListener(idleObserver);
  replication.start();
  boolean success=replicationIdle.await(30,TimeUnit.SECONDS);
  assertTrue(success);
  replication.removeChangeListener(idleObserver);
  Document doc1=createDocumentForPushReplication("String_Node_Str",null,null);
  int numAttempts=RemoteRequestRetry.MAX_RETRIES + 1;
  for (int i=0; i < numAttempts; i++) {
    RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(request);
    dispatcher.takeRecordedResponseBlocking(request);
  }
  for (int j=0; j < RemoteRequestRetry.MAX_RETRIES; j++) {
    for (int i=0; i < numAttempts; i++) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_BULK_DOCS);
      assertNotNull(request);
      dispatcher.takeRecordedResponseBlocking(request);
    }
  }
  stopReplication(replication);
  server.shutdown();
}

Fixed version (ground truth):
/** 
 * Make sure that if a continuous push gets an error pushing a doc, it will keep retrying it rather than giving up right away.
 * @throws Exception
 */
public void testContinuousPushRetryBehavior() throws Exception {
  RemoteRequestRetry.RETRY_DELAY_MS=5;
  ReplicationInternal.RETRY_DELAY_SECONDS=1;
  ReplicationInternal.MAX_RETRIES=3;
  MockDispatcher dispatcher=new MockDispatcher();
  MockWebServer server=MockHelper.getMockWebServer(dispatcher);
  dispatcher.setServerType(MockDispatcher.ServerType.SYNC_GW);
  MockCheckpointPut mockCheckpointPut=new MockCheckpointPut();
  mockCheckpointPut.setSticky(true);
  mockCheckpointPut.setDelayMs(500);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_CHECKPOINT,mockCheckpointPut);
  MockRevsDiff mockRevsDiff=new MockRevsDiff();
  mockRevsDiff.setSticky(true);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_REVS_DIFF,mockRevsDiff);
  MockResponse mockResponse=new MockResponse().setResponseCode(503);
  WrappedSmartMockResponse mockBulkDocs=new WrappedSmartMockResponse(mockResponse,false);
  mockBulkDocs.setSticky(true);
  dispatcher.enqueueResponse(MockHelper.PATH_REGEX_BULK_DOCS,mockBulkDocs);
  server.play();
  Replication replication=database.createPushReplication(server.getUrl("String_Node_Str"));
  replication.setContinuous(true);
  CountDownLatch replicationIdle=new CountDownLatch(1);
  ReplicationIdleObserver idleObserver=new ReplicationIdleObserver(replicationIdle);
  replication.addChangeListener(idleObserver);
  replication.start();
  boolean success=replicationIdle.await(30,TimeUnit.SECONDS);
  assertTrue(success);
  replication.removeChangeListener(idleObserver);
  Document doc1=createDocumentForPushReplication("String_Node_Str",null,null);
  int numAttempts=RemoteRequestRetry.MAX_RETRIES + 1;
  for (int i=0; i < numAttempts; i++) {
    RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_BULK_DOCS);
    assertNotNull(request);
    dispatcher.takeRecordedResponseBlocking(request);
  }
  for (int j=0; j < ReplicationInternal.MAX_RETRIES; j++) {
    for (int i=0; i < numAttempts; i++) {
      RecordedRequest request=dispatcher.takeRequestBlocking(MockHelper.PATH_REGEX_BULK_DOCS);
      assertNotNull(request);
      dispatcher.takeRecordedResponseBlocking(request);
    }
  }
  stopReplication(replication);
  server.shutdown();
}