@Test(timeout = 5000)
public void testRaceCondition() throws InterruptedException {

    int parties = 2;
    final AtomicInteger barrierGenerations = new AtomicInteger();
    final CyclicBarrier barrier = new CyclicBarrier(parties, new Runnable() {
        @Override
        public void run() {
            int generation = barrierGenerations.incrementAndGet();
        }
    });
    final ArrayBlockingQueue<Throwable> caught = new ArrayBlockingQueue<>(1);
    final AtomicBoolean running = new AtomicBoolean(true);
    // We start 2 threads with a cyclic barrier repeatedly and wait a collision with at least one
    long endBy = System.currentTimeMillis() + 5000;
    for (int i = 0; i < parties; i++) {
        new CyclicBarrierThread(barrier, caught, running, endBy).start();
    }
    //noinspection ThrowableResultOfMethodCallIgnored
    assertEquals("Failed to add new SpanSink, concurrent add", caught.poll(5000, TimeUnit.MILLISECONDS).getMessage());
    int sinks = ImmutableList.copyOf(SpanSinkRegistry.getSpanSinks()).size();
    int totalAdds = barrierGenerations.get() * 2;
    assertTrue(sinks + " < " + totalAdds + "?", totalAdds > sinks);
}