Skip to content

Commit a0eb3f5

Browse files
committed
=tck check isCancelled in 205 blackbox; sample the state sometimes
1 parent 5fc82d7 commit a0eb3f5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,22 @@ public void run(BlackboxTestStage stage) throws InterruptedException {
100100
final long signalsToEmit = Math.min(requested, 512); // protecting against Subscriber which sends ridiculous large demand
101101

102102
// should cope with up to requested number of elements
103-
for (int i = 0; i < signalsToEmit; i++)
103+
for (int i = 0; i < signalsToEmit && sampleIsCancelled(stage, i, 10); i++)
104104
stage.signalNext();
105105

106106
// we complete after `signalsToEmit` (which can be less than `requested`),
107107
// which is legal under https://github.com/reactive-streams/reactive-streams-jvm#1.2
108108
stage.sendCompletion();
109109
}
110+
111+
/**
112+
* In order to allow some "skid" and not check state on each iteration,
113+
* only check {@code stage.isCancelled} every {@code checkInterval}'th iteration.
114+
*/
115+
private boolean sampleIsCancelled(BlackboxTestStage stage, int i, int checkInterval) throws InterruptedException {
116+
if (i % checkInterval == 0) return stage.isCancelled();
117+
else return false;
118+
}
110119
});
111120
}
112121

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

+4
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,10 @@ public void expectCancelling() throws InterruptedException {
775775
public void expectCancelling(long timeoutMillis) throws InterruptedException {
776776
cancelled.expectClose(timeoutMillis, "Did not receive expected cancelling of upstream subscription");
777777
}
778+
779+
public boolean isCancelled() throws InterruptedException {
780+
return cancelled.isClosed();
781+
}
778782
}
779783

780784
/**

0 commit comments

Comments
 (0)