|
18 | 18 |
|
19 | 19 | import java.time.Duration; |
20 | 20 | import java.util.List; |
| 21 | +import java.util.concurrent.atomic.AtomicBoolean; |
21 | 22 | import java.util.concurrent.atomic.AtomicInteger; |
22 | 23 |
|
23 | 24 | import org.assertj.core.api.Assertions; |
24 | 25 | import org.assertj.core.util.Lists; |
25 | 26 | import org.awaitility.Awaitility; |
26 | | -import org.junit.Ignore; |
27 | 27 | import org.junit.jupiter.api.AfterEach; |
28 | 28 | import org.junit.jupiter.api.BeforeEach; |
29 | 29 | import org.junit.jupiter.api.Test; |
@@ -467,27 +467,31 @@ protected Flux<List<ServiceInstance>> healthCheckFlux( |
467 | 467 | Assertions.assertThat(emitCounter).hasValue(1); |
468 | 468 | } |
469 | 469 |
|
470 | | - @Ignore // Fixme: see https://github.com/spring-cloud/spring-cloud-commons/issues/716 |
471 | 470 | @Test |
472 | 471 | void shouldCancelSubscription() { |
473 | 472 |
|
474 | 473 | final AtomicInteger instancesCanceled = new AtomicInteger(); |
475 | | - |
| 474 | + final AtomicBoolean subscribed = new AtomicBoolean(); |
476 | 475 | ServiceInstanceListSupplier delegate = Mockito |
477 | 476 | .mock(ServiceInstanceListSupplier.class); |
478 | | - Mockito.when(delegate.get()).thenReturn(Flux.<List<ServiceInstance>>never() |
479 | | - .log("test").doOnCancel(instancesCanceled::incrementAndGet)); |
| 477 | + Mockito.when(delegate.get()) |
| 478 | + .thenReturn(Flux.<List<ServiceInstance>>never() |
| 479 | + .doOnSubscribe(subscription -> subscribed.set(true)) |
| 480 | + .doOnCancel(instancesCanceled::incrementAndGet)); |
480 | 481 |
|
481 | 482 | listSupplier = new HealthCheckServiceInstanceListSupplier(delegate, healthCheck, |
482 | 483 | webClient); |
483 | 484 |
|
484 | 485 | listSupplier.afterPropertiesSet(); |
485 | 486 |
|
| 487 | + Awaitility.await("delegate subscription").pollDelay(Duration.ofMillis(50)) |
| 488 | + .atMost(VERIFY_TIMEOUT).untilTrue(subscribed); |
| 489 | + |
486 | 490 | Assertions.assertThat(instancesCanceled).hasValue(0); |
487 | 491 |
|
488 | 492 | listSupplier.destroy(); |
489 | | - Awaitility.await().pollDelay(Duration.ofMillis(100)).atMost(VERIFY_TIMEOUT) |
490 | | - .untilAsserted( |
| 493 | + Awaitility.await("delegate cancellation").pollDelay(Duration.ofMillis(100)) |
| 494 | + .atMost(VERIFY_TIMEOUT).untilAsserted( |
491 | 495 | () -> Assertions.assertThat(instancesCanceled).hasValue(1)); |
492 | 496 | } |
493 | 497 |
|
|
0 commit comments