[bluetooth] Try to make tests more stable No.2 (#9309)

* [bluetooth] Try to make tests more stable No.2

Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
Fabian Wolter 2020-12-10 01:16:40 +01:00 committed by GitHub
parent 3bd17f4788
commit 941189ad55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -115,7 +115,7 @@ class RetryFutureTest {
} }
@Test @Test
void composeWithRetry1() throws InterruptedException { void composeWithRetry1() {
AtomicInteger visitCount = new AtomicInteger(); AtomicInteger visitCount = new AtomicInteger();
CompletableFuture<String> composedFuture = new CompletableFuture<>(); CompletableFuture<String> composedFuture = new CompletableFuture<>();
Future<String> retryFuture = RetryFuture.composeWithRetry(() -> { Future<String> retryFuture = RetryFuture.composeWithRetry(() -> {
@ -152,11 +152,12 @@ class RetryFutureTest {
if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) { if (!latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
fail("Timeout while waiting for latch"); fail("Timeout while waiting for latch");
} }
Thread.sleep(1); Future<Boolean> future = scheduler.submit(() -> {
retryFuture.cancel(false); retryFuture.cancel(false);
return composedFuture.isCancelled();
assertTrue(composedFuture.isCancelled()); });
} catch (InterruptedException e) { assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e); fail(e);
} }
assertEquals(2, visitCount.get()); assertEquals(2, visitCount.get());