@Test
public void testSessionStartRaceCondition() throws Exception {

    final List<TrackMe> trackMes = Collections.synchronizedList(new ArrayList<TrackMe>());
    doAnswer(invocation -> {
        trackMes.add(invocation.getArgument(0));
        return null;
    }).when(mDispatcher).submit(any(TrackMe.class));
    when(mDispatcher.getConnectionTimeOut()).thenReturn(1000);
    for (int i = 0; i < 1000; i++) {
        trackMes.clear();
        final Tracker tracker = new Tracker(mMatomo, mTrackerBuilder);
        final CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int j = 0; j < 10; j++) {
            new Thread(() -> {
                try {
                    TestHelper.sleep(new Random().nextInt(4 - 0) + 0);
                    TrackMe trackMe = new TrackMe()
                            .set(QueryParams.EVENT_ACTION, UUID.randomUUID().toString())
                            .set(QueryParams.EVENT_CATEGORY, UUID.randomUUID().toString())
                            .set(QueryParams.EVENT_NAME, UUID.randomUUID().toString())
                            .set(QueryParams.EVENT_VALUE, 1);
                    tracker.track(trackMe);
                    countDownLatch.countDown();
                } catch (Exception e) {
                    e.printStackTrace();
                    assertFalse(true);
                }
            }).start();
        }
        countDownLatch.await();
        for (TrackMe out : trackMes) {
            if (trackMes.indexOf(out) == 0) {
                assertTrue(i + "#" + out.toMap().size(), out.get(QueryParams.LANGUAGE) != null);
                assertTrue(out.get(QueryParams.FIRST_VISIT_TIMESTAMP) != null);
                assertTrue(out.get(SESSION_START) != null);
            } else {
                assertTrue(out.get(QueryParams.LANGUAGE) == null);
                assertTrue(out.get(QueryParams.FIRST_VISIT_TIMESTAMP) == null);
                assertTrue(out.get(SESSION_START) == null);
            }
        }
    }
}