]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth] Try to make tests more stable (#9304)
authorFabian Wolter <github@fabian-wolter.de>
Wed, 9 Dec 2020 14:07:55 +0000 (15:07 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Dec 2020 14:07:55 +0000 (15:07 +0100)
Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/util/RetryFutureTest.java

index b16621a5b5b4f0e416ed76f33a1dabc9278284b7..dde898adf7aceee61279560ed4740141e9c10e86 100644 (file)
@@ -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<String> 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<String> 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<String> 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);