From 4c1a94ea7454c2a8105b210f2915e5eee6b67a4f Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Thu, 21 May 2026 08:36:06 -0300 Subject: [PATCH] test: spin until the thread reaches barrier.await Close #197 --- .../addons/gridexporter/test/ConcurrentExportTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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; }