diff --git a/src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/ConcurrentExportTests.java b/src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/ConcurrentExportTests.java index 7d67b86..1d8fbaf 100644 --- a/src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/ConcurrentExportTests.java +++ b/src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/ConcurrentExportTests.java @@ -279,6 +279,14 @@ public MockDownload await() throws InterruptedException { thread.start(); } latch.await(); + // Spin until the thread reaches barrier.await() (WAITING state). + // latch.countDown() happens before barrier.await(), so there is a window + // where latch==0 but the thread hasn't entered the barrier yet. + // Assumes the barrier has not fired yet; otherwise WAITING could mean + // exchanger.exchange() rather than barrier.await(). + while (thread.isAlive() && thread.getState() != Thread.State.WAITING) { + Thread.onSpinWait(); + } return this; }