Skip to content

Commit

Permalink
Fixing blinking tests (ReactiveX#173)
Browse files Browse the repository at this point in the history
* Fixing blinking test in AsyncRetryEventPublisherTest

* Removing race condition from 'RateLimiterChainSpec.test events' test
  • Loading branch information
Jan Sykora authored and RobWin committed Nov 2, 2017
1 parent 077e1e2 commit 003ab53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ class RateLimiterChainSpec extends Specification {
}

and:
['test1', 'test2'].each {
def r = rateLimiterRegistry.rateLimiter(it)
assert r.metrics.availablePermissions == 0
}
await().atMost(2, TimeUnit.SECONDS).until {
['test1', 'test2'].each {
def r = rateLimiterRegistry.rateLimiter(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@

import javax.xml.ws.WebServiceException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static io.github.resilience4j.retry.utils.AsyncUtils.awaitResult;
import static io.vavr.API.*;
import static io.vavr.API.$;
import static io.vavr.API.Case;
import static io.vavr.API.Match;
import static io.vavr.Predicates.instanceOf;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -62,22 +66,27 @@ public void shouldReturnTheSameConsumer() {
}

@Test
public void shouldConsumeOnSuccessEvent() {
public void shouldConsumeOnSuccessEvent() throws Exception {
CompletableFuture<String> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(new WebServiceException("BAM!"));

CountDownLatch latch = new CountDownLatch(1);

// Given the HelloWorldService returns Hello world
given(helloWorldService.returnHelloWorld())
.willReturn(failedFuture)
.willReturn(completedFuture("Hello world"));

retry.getEventPublisher()
.onSuccess(event ->
logger.info(event.getEventType().toString()));
.onSuccess(event -> {
logger.info(event.getEventType().toString());
latch.countDown();
});

String result = awaitResult(retry.executeCompletionStage(scheduler,
() -> helloWorldService.returnHelloWorld()));

assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(result).isEqualTo("Hello world");
then(helloWorldService).should(times(2)).returnHelloWorld();
then(logger).should(times(1)).info("SUCCESS");
Expand Down

0 comments on commit 003ab53

Please sign in to comment.