From 428bddcd4922f20a19f9776e1fb27c9e07aa4362 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Mon, 29 May 2017 17:26:25 +0200 Subject: [PATCH] +tck #362 complete subscriber under test once done in 205 --- .../tck/SubscriberBlackboxVerification.java | 1 + .../SubscriberBlackboxVerificationTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java b/tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java index d3af02b9..18f8e8a7 100644 --- a/tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java +++ b/tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java @@ -219,6 +219,7 @@ public String toString() { secondSubscriptionCancelled.expectClose("Expected SecondSubscription given to subscriber to be cancelled, but `Subscription.cancel()` was not called."); env.verifyNoAsyncErrorsNoDelay(); + sendCompletion(); // we're done, complete the subscriber under test }}; } diff --git a/tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java b/tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java index 38703f7d..0ddebaa3 100644 --- a/tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java +++ b/tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java @@ -18,8 +18,10 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; /** * Validates that the TCK's {@link org.reactivestreams.tck.SubscriberBlackboxVerification} fails with nice human readable errors. @@ -111,6 +113,34 @@ public void required_spec205_blackbox_mustCallSubscriptionCancelIfItAlreadyHasAn }, "illegally called `subscription.request(1)"); } + @Test + public void required_spec205_blackbox_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal_shouldGetCompletion() throws Throwable { + final CountDownLatch completion = new CountDownLatch(1); + + customSubscriberVerification(new KeepSubscriptionSubscriber() { + volatile Subscription sub; + + @Override + public void onSubscribe(Subscription s) { + super.onSubscribe(s); + if (sub != null) { + sub = s; + s.request(1); + } else { + // the second one we cancel + s.cancel(); + } + } + + @Override + public void onComplete() { + completion.countDown(); + } + }).required_spec205_blackbox_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal(); + + completion.await(1, TimeUnit.SECONDS); + } + @Test public void required_spec209_blackbox_mustBePreparedToReceiveAnOnCompleteSignalWithPrecedingRequestCall_shouldFail() throws Throwable { requireTestFailure(new ThrowingRunnable() {