Skip to content

Commit 0e3ea33

Browse files
authored
try to fix flaky test (#718)
fixes gh-716
1 parent de9882c commit 0e3ea33

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/HealthCheckServiceInstanceListSupplierTests.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import java.time.Duration;
2020
import java.util.List;
21+
import java.util.concurrent.atomic.AtomicBoolean;
2122
import java.util.concurrent.atomic.AtomicInteger;
2223

2324
import org.assertj.core.api.Assertions;
2425
import org.assertj.core.util.Lists;
2526
import org.awaitility.Awaitility;
26-
import org.junit.Ignore;
2727
import org.junit.jupiter.api.AfterEach;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
@@ -467,27 +467,31 @@ protected Flux<List<ServiceInstance>> healthCheckFlux(
467467
Assertions.assertThat(emitCounter).hasValue(1);
468468
}
469469

470-
@Ignore // Fixme: see https://github.com/spring-cloud/spring-cloud-commons/issues/716
471470
@Test
472471
void shouldCancelSubscription() {
473472

474473
final AtomicInteger instancesCanceled = new AtomicInteger();
475-
474+
final AtomicBoolean subscribed = new AtomicBoolean();
476475
ServiceInstanceListSupplier delegate = Mockito
477476
.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));
480481

481482
listSupplier = new HealthCheckServiceInstanceListSupplier(delegate, healthCheck,
482483
webClient);
483484

484485
listSupplier.afterPropertiesSet();
485486

487+
Awaitility.await("delegate subscription").pollDelay(Duration.ofMillis(50))
488+
.atMost(VERIFY_TIMEOUT).untilTrue(subscribed);
489+
486490
Assertions.assertThat(instancesCanceled).hasValue(0);
487491

488492
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(
491495
() -> Assertions.assertThat(instancesCanceled).hasValue(1));
492496
}
493497

0 commit comments

Comments
 (0)