Skip to content

=tck #362 signal onComplete in 201 blackbox verification #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,25 @@ public void required_spec201_blackbox_mustSignalDemandViaSubscriptionRequest() t
@Override
public void run(BlackboxTestStage stage) throws InterruptedException {
triggerRequest(stage.subProxy().sub());
final long n = stage.expectRequest();// assuming subscriber wants to consume elements...
final long requested = stage.expectRequest();// assuming subscriber wants to consume elements...
final long signalsToEmit = Math.min(requested, 512); // protecting against Subscriber which sends ridiculous large demand
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could be TestEnvironment.TEST_BUFFER_SIZE, anything less than huge numbers is fine here though IMO


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

// we complete after `signalsToEmit` (which can be less than `requested`),
// which is legal under https://github.com/reactive-streams/reactive-streams-jvm#1.2
stage.sendCompletion();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we sendCompletion() even if cancelled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? Cancellation is allowed to be "racy"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the "polite" implementation would check if it is not cancelled before issuing the completion. (so that the implementation does not rely on onComplete if cancelled)

}

/**
* In order to allow some "skid" and not check state on each iteration,
* only check {@code stage.isCancelled} every {@code checkInterval}'th iteration.
*/
private boolean sampleIsCancelled(BlackboxTestStage stage, int i, int checkInterval) throws InterruptedException {
if (i % checkInterval == 0) return stage.isCancelled();
else return false;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ public void expectCancelling() throws InterruptedException {
public void expectCancelling(long timeoutMillis) throws InterruptedException {
cancelled.expectClose(timeoutMillis, "Did not receive expected cancelling of upstream subscription");
}

public boolean isCancelled() throws InterruptedException {
return cancelled.isClosed();
}
}

/**
Expand Down