Skip to content

Commit 428bddc

Browse files
committed
+tck #362 complete subscriber under test once done in 205
1 parent 2879ce0 commit 428bddc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: tck/src/main/java/org/reactivestreams/tck/SubscriberBlackboxVerification.java

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public String toString() {
219219

220220
secondSubscriptionCancelled.expectClose("Expected SecondSubscription given to subscriber to be cancelled, but `Subscription.cancel()` was not called.");
221221
env.verifyNoAsyncErrorsNoDelay();
222+
sendCompletion(); // we're done, complete the subscriber under test
222223
}};
223224
}
224225

Diff for: tck/src/test/java/org/reactivestreams/tck/SubscriberBlackboxVerificationTest.java

+30
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import org.testng.annotations.BeforeClass;
1919
import org.testng.annotations.Test;
2020

21+
import java.util.concurrent.CountDownLatch;
2122
import java.util.concurrent.ExecutorService;
2223
import java.util.concurrent.Executors;
24+
import java.util.concurrent.TimeUnit;
2325

2426
/**
2527
* 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
111113
}, "illegally called `subscription.request(1)");
112114
}
113115

116+
@Test
117+
public void required_spec205_blackbox_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal_shouldGetCompletion() throws Throwable {
118+
final CountDownLatch completion = new CountDownLatch(1);
119+
120+
customSubscriberVerification(new KeepSubscriptionSubscriber() {
121+
volatile Subscription sub;
122+
123+
@Override
124+
public void onSubscribe(Subscription s) {
125+
super.onSubscribe(s);
126+
if (sub != null) {
127+
sub = s;
128+
s.request(1);
129+
} else {
130+
// the second one we cancel
131+
s.cancel();
132+
}
133+
}
134+
135+
@Override
136+
public void onComplete() {
137+
completion.countDown();
138+
}
139+
}).required_spec205_blackbox_mustCallSubscriptionCancelIfItAlreadyHasAnSubscriptionAndReceivesAnotherOnSubscribeSignal();
140+
141+
completion.await(1, TimeUnit.SECONDS);
142+
}
143+
114144
@Test
115145
public void required_spec209_blackbox_mustBePreparedToReceiveAnOnCompleteSignalWithPrecedingRequestCall_shouldFail() throws Throwable {
116146
requireTestFailure(new ThrowingRunnable() {

0 commit comments

Comments
 (0)