From 941189ad5552d4657485856bc795e047435a5d7e Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Thu, 10 Dec 2020 01:16:40 +0100 Subject: [PATCH] [bluetooth] Try to make tests more stable No.2 (#9309) * [bluetooth] Try to make tests more stable No.2 Signed-off-by: Fabian Wolter --- .../binding/bluetooth/util/RetryFutureTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/util/RetryFutureTest.java b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/util/RetryFutureTest.java index dde898adf..40bf1fe1a 100644 --- a/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/util/RetryFutureTest.java +++ b/bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/util/RetryFutureTest.java @@ -115,7 +115,7 @@ class RetryFutureTest { } @Test - void composeWithRetry1() throws InterruptedException { + void composeWithRetry1() { AtomicInteger visitCount = new AtomicInteger(); CompletableFuture composedFuture = new CompletableFuture<>(); Future retryFuture = RetryFuture.composeWithRetry(() -> { @@ -152,11 +152,12 @@ class RetryFutureTest { if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { fail("Timeout while waiting for latch"); } - Thread.sleep(1); - retryFuture.cancel(false); - - assertTrue(composedFuture.isCancelled()); - } catch (InterruptedException e) { + Future future = scheduler.submit(() -> { + retryFuture.cancel(false); + return composedFuture.isCancelled(); + }); + assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); + } catch (InterruptedException | ExecutionException | TimeoutException e) { fail(e); } assertEquals(2, visitCount.get());