From 3069d9cc63a8bdc864cdc8389702b1e79f8da1a3 Mon Sep 17 00:00:00 2001 From: Remco Westerhoud Date: Wed, 12 Jan 2022 16:32:35 +0100 Subject: [PATCH] fix: Tests no longer randomly get stuck when waiting for idle state --- .../test/testengine/IdleStateMonitor.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/camunda/zeebe/process/test/testengine/IdleStateMonitor.java b/src/main/java/io/camunda/zeebe/process/test/testengine/IdleStateMonitor.java index 49bb3d56..555842cf 100644 --- a/src/main/java/io/camunda/zeebe/process/test/testengine/IdleStateMonitor.java +++ b/src/main/java/io/camunda/zeebe/process/test/testengine/IdleStateMonitor.java @@ -52,29 +52,27 @@ public void addCallback(final Runnable callback) { } private void checkIdleState() { - if (isInIdleState()) { - scheduleNotification(); - } else { - cancelNotification(); + synchronized (idleStateNotifier) { + if (isInIdleState()) { + scheduleNotification(); + } else { + cancelNotification(); + } } } private void scheduleNotification() { - synchronized (idleStateNotifier) { - idleStateNotifier = createIdleStateNotifier(); - try { - TIMER.schedule(idleStateNotifier, GRACE_PERIOD); - } catch (IllegalStateException e) { - // thrown - among others - if task was cancelled before it could be scheduled - // do nothing in this case - } + idleStateNotifier = createIdleStateNotifier(); + try { + TIMER.schedule(idleStateNotifier, GRACE_PERIOD); + } catch (IllegalStateException e) { + // thrown - among others - if task was cancelled before it could be scheduled + // do nothing in this case } } private void cancelNotification() { - synchronized (idleStateNotifier) { - idleStateNotifier.cancel(); - } + idleStateNotifier.cancel(); } private boolean isInIdleState() {