From 6cadc2e166d11fb31de2c00ff2ac3281ddbdf6ab Mon Sep 17 00:00:00 2001 From: Thang PHAM Date: Tue, 20 Jan 2026 15:43:45 +0100 Subject: [PATCH] Avoid hangout when exception in async test Signed-off-by: Thang PHAM --- .../controller/DynamicSimulationControllerTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java index 3623250..e23bdaa 100644 --- a/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java +++ b/src/test/java/org/gridsuite/ds/server/controller/DynamicSimulationControllerTest.java @@ -448,8 +448,12 @@ private UUID runAndCancel(CountDownLatch cancelLatch, int cancelDelay) throws Ex assertRunningStatus(runUuid); - // stop dynamic simulation - cancelLatch.await(); + // stop dynamic simulation, need a timeout to avoid test hangs if an exception occurs before latch countdown + boolean completed = cancelLatch.await(5, TimeUnit.SECONDS); + if (!completed) { + throw new AssertionError("Timed out waiting for cancelLatch, something might have crashed before latch countdown happens."); + } + // custom additional wait await().pollDelay(cancelDelay, TimeUnit.MILLISECONDS).until(() -> true);