@Test
  public void testRestartProducerOnLateCancellationCallback() {
    mMultiplexProducer.produceResults(mConsumer1, mProducerContext1);
    verify(mInputProducer).produceResults(mForwardingConsumer1, mMultiplexedContext1);
    mProducerContext1.cancel();
    verify(mConsumer1).onCancellation();
    mMultiplexProducer.produceResults(mConsumer2, mProducerContext2);
    verify(mInputProducer).produceResults(any(Consumer.class), any(ProducerContext.class));
    mForwardingConsumer1.onCancellation();
    assertEquals(1, mMultiplexProducer.mMultiplexers.size());
    verify(mInputProducer).produceResults(mForwardingConsumer2, mMultiplexedContext2);
    mForwardingConsumer2.onNewResult(mFinalImageReference1, Consumer.IS_LAST);
    verify(mConsumer2).onNewResult(mFinalImageReference1, Consumer.IS_LAST);
    assertTrue(mMultiplexProducer.mMultiplexers.isEmpty());
  }
An extra flag to check we maintain other flags than just whether this is the last result
imagepipeline/src/test/java/com/facebook/imagepipeline/producers/MultiplexProducerTest.java