Program: 81199
Project: 81199
Buggy source:
/** 
 * Test to verify the retry policy for 5XX errors
 * @throws IOException
 * @throws SerializeException
 */
@Test public void test5XXRetryPolicy() throws IOException, SerializeException {
  Context context=RuntimeEnvironment.application;
  File file=createRandomFile();
  HandlerThread handlerThread=new HandlerThread(createRandomString());
  handlerThread.start();
  Looper looper=handlerThread.getLooper();
  Handler handler=new Handler(looper);
  ShadowLooper shadowLooper=Shadows.shadowOf(looper);
  SizeBatchingStrategy strategy=mock(SizeBatchingStrategy.class);
  SizeBatchingStrategy.SizeBatch<Data> firstBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  SerializationStrategy serializationStrategy=new GsonSerializationStrategy();
  BatchManager.registerBuiltInTypes(serializationStrategy);
  serializationStrategy.build();
  int ERROR_CODE_5XX=500;
  long callbackIdle=1000;
  MockNetworkPersistedBatchReadyListener networkBatchListener=spy(new MockNetworkPersistedBatchReadyListener(new NetworkPersistedBatchReadyListener.NetworkRequestResponse(true,ERROR_CODE_5XX),handler,callbackIdle,context));
  int maxRetryCount=5;
  NetworkPersistedBatchReadyListener networkPersistedBatchReadyListener=new NetworkPersistedBatchReadyListener(context,file,serializationStrategy,handler,networkBatchListener,maxRetryCount);
  networkPersistedBatchReadyListener.onReady(strategy,firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(1)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(5000);
  verify(networkBatchListener,times(2)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + 10000);
  verify(networkBatchListener,times(3)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + 20000);
  verify(networkBatchListener,times(4)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + 40000);
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + 80000);
  ArgumentCaptor<ValueCallback> valueCallbackCapture=ArgumentCaptor.forClass(ValueCallback.class);
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),valueCallbackCapture.capture());
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  NetworkPersistedBatchReadyListener.NetworkRequestResponse requestResponse=new NetworkPersistedBatchReadyListener.NetworkRequestResponse(true,200);
  valueCallbackCapture.getValue().onReceiveValue(requestResponse);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  networkPersistedBatchReadyListener.onReady(strategy,firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(6)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(5000);
  verify(networkBatchListener,times(7)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
}

Fixed version (ground truth):
/** 
 * Test to verify the retry policy for 5XX errors
 * @throws IOException
 * @throws SerializeException
 */
@Test public void test5XXRetryPolicy() throws IOException, SerializeException {
  Context context=RuntimeEnvironment.application;
  File file=createRandomFile();
  HandlerThread handlerThread=new HandlerThread(createRandomString());
  handlerThread.start();
  Looper looper=handlerThread.getLooper();
  Handler handler=new Handler(looper);
  ShadowLooper shadowLooper=Shadows.shadowOf(looper);
  SizeBatchingStrategy strategy=mock(SizeBatchingStrategy.class);
  SizeBatchingStrategy.SizeBatch<Data> firstBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  SerializationStrategy serializationStrategy=new GsonSerializationStrategy();
  BatchManager.registerBuiltInTypes(serializationStrategy);
  serializationStrategy.build();
  int ERROR_CODE_5XX=500;
  long callbackIdle=1000;
  MockNetworkPersistedBatchReadyListener networkBatchListener=spy(new MockNetworkPersistedBatchReadyListener(new NetworkPersistedBatchReadyListener.NetworkRequestResponse(true,ERROR_CODE_5XX),handler,callbackIdle,context));
  int maxRetryCount=5;
  NetworkPersistedBatchReadyListener networkPersistedBatchReadyListener=new NetworkPersistedBatchReadyListener(context,file,serializationStrategy,handler,networkBatchListener,maxRetryCount);
  networkPersistedBatchReadyListener.onReady(strategy,firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(1)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(networkPersistedBatchReadyListener.getDefaultTimeoutMs());
  verify(networkBatchListener,times(2)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + networkPersistedBatchReadyListener.getDefaultTimeoutMs() * 2);
  verify(networkBatchListener,times(3)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + networkPersistedBatchReadyListener.getDefaultTimeoutMs() * 4);
  verify(networkBatchListener,times(4)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + networkPersistedBatchReadyListener.getDefaultTimeoutMs() * 8);
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(callbackIdle + networkPersistedBatchReadyListener.getDefaultTimeoutMs() * 16);
  ArgumentCaptor<ValueCallback> valueCallbackCapture=ArgumentCaptor.forClass(ValueCallback.class);
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),valueCallbackCapture.capture());
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  NetworkPersistedBatchReadyListener.NetworkRequestResponse requestResponse=new NetworkPersistedBatchReadyListener.NetworkRequestResponse(true,200);
  valueCallbackCapture.getValue().onReceiveValue(requestResponse);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(5)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  networkPersistedBatchReadyListener.onReady(strategy,firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(networkBatchListener,times(6)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
  shadowLooper.idle(networkPersistedBatchReadyListener.getDefaultTimeoutMs());
  verify(networkBatchListener,times(7)).performNetworkRequest(any(Batch.class),any(ValueCallback.class));
}