From aba5e2c9964004aeeeb0e411a09e0377c22a8817 Mon Sep 17 00:00:00 2001 From: Fabian Wolter Date: Wed, 9 Dec 2020 15:07:55 +0100 Subject: [PATCH] [bluetooth] Try to make tests more stable (#9304) Signed-off-by: Fabian Wolter --- .../bluetooth/util/RetryFutureTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 b16621a5b5b..dde898adf7a 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 @@ -35,6 +35,7 @@ import org.openhab.core.common.NamedThreadFactory; */ class RetryFutureTest { + private static final int TIMEOUT_MS = 1000; private ScheduledExecutorService scheduler; @BeforeEach @@ -52,17 +53,17 @@ class RetryFutureTest { } @Test - void callWithRetryNormal() throws InterruptedException { + void callWithRetryNormal() { Future retryFuture = RetryFuture.callWithRetry(() -> "test", scheduler); try { - assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS)); + assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException | ExecutionException | TimeoutException e) { fail(e); } } @Test - void callWithRetry1() throws InterruptedException { + void callWithRetry1() { AtomicInteger visitCount = new AtomicInteger(); Future retryFuture = RetryFuture.callWithRetry(() -> { if (visitCount.getAndIncrement() == 0) { @@ -71,14 +72,14 @@ class RetryFutureTest { return "test"; }, scheduler); try { - assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS)); + assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException | ExecutionException | TimeoutException e) { fail(e); } } @Test - void composeWithRetryNormal() throws InterruptedException { + void composeWithRetryNormal() { CompletableFuture composedFuture = new CompletableFuture<>(); Future retryFuture = RetryFuture.composeWithRetry(() -> { @@ -87,7 +88,7 @@ class RetryFutureTest { }, scheduler); try { - retryFuture.get(100, TimeUnit.MILLISECONDS); + retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { fail(e); } @@ -95,7 +96,7 @@ class RetryFutureTest { } @Test - void composeWithRetryThrow() throws InterruptedException { + void composeWithRetryThrow() { CompletableFuture composedFuture = new CompletableFuture<>(); Future retryFuture = RetryFuture.composeWithRetry(() -> { @@ -104,7 +105,7 @@ class RetryFutureTest { }, scheduler); try { - retryFuture.get(100, TimeUnit.MILLISECONDS); + retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (InterruptedException | TimeoutException e) { fail(e); } catch (ExecutionException ex) { @@ -126,7 +127,7 @@ class RetryFutureTest { }, scheduler); try { - assertEquals("test", retryFuture.get(100, TimeUnit.MILLISECONDS)); + assertEquals("test", retryFuture.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); } catch (InterruptedException | ExecutionException | TimeoutException e) { fail(e); } @@ -135,7 +136,7 @@ class RetryFutureTest { } @Test - void composeWithRetry1Cancel() throws InterruptedException { + void composeWithRetry1Cancel() { CountDownLatch latch = new CountDownLatch(1); AtomicInteger visitCount = new AtomicInteger(); CompletableFuture composedFuture = new CompletableFuture<>(); @@ -148,7 +149,7 @@ class RetryFutureTest { }, scheduler); try { - if (!latch.await(100, TimeUnit.MILLISECONDS)) { + if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { fail("Timeout while waiting for latch"); } Thread.sleep(1);