]> git.basschouten.com Git - openhab-addons.git/commitdiff
[bluetooth] Try to make tests more stable No.2 (#9309)
authorFabian Wolter <github@fabian-wolter.de>
Thu, 10 Dec 2020 00:16:40 +0000 (01:16 +0100)
committerGitHub <noreply@github.com>
Thu, 10 Dec 2020 00:16:40 +0000 (16:16 -0800)
* [bluetooth] Try to make tests more stable No.2

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 dde898adf7aceee61279560ed4740141e9c10e86..40bf1fe1a150cfedfb8d83049e70230a19370281 100644 (file)
@@ -115,7 +115,7 @@ class RetryFutureTest {
     }
 
     @Test
-    void composeWithRetry1() throws InterruptedException {
+    void composeWithRetry1() {
         AtomicInteger visitCount = new AtomicInteger();
         CompletableFuture<String> composedFuture = new CompletableFuture<>();
         Future<String> 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<Boolean> 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());