Skip to content

Wait for demand before signaling onNext #441

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

Conversation

jroper
Copy link
Contributor

@jroper jroper commented Nov 18, 2018

Fixes #277.

Fixes two whitebox subscriber tests where they weren't waiting for demand before signaling onNext.

Fixes reactive-streams#277.

Fixes two whitebox subscriber tests where they weren't waiting for
demand before signaling onNext.
Copy link
Contributor

@viktorklang viktorklang left a comment

Choose a reason for hiding this comment

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

Looks ok to me!

@reactive-streams/contributors Please review.

@viktorklang viktorklang added this to the 1.0.3 milestone Nov 19, 2018
@@ -267,6 +267,7 @@ public void required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCall
public void run(WhiteboxTestStage stage) throws InterruptedException {
stage.puppet().triggerRequest(1);
stage.puppet().signalCancel();
stage.expectRequest();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be there an unit test that failed before this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this some more, shouldn't the expectRequest be before the signalCancel?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also could it be possible, and legal, that a request followed by a cancel is coalesced into just a cancel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be there an unit test that failed before this change?

I'll add one.

Thinking about this some more, shouldn't the expectRequest be before the signalCancel?:

I don't think it matters, in fact the reason I put it in this order is that I think this order makes it more likely that the test will test what it's intending to test. Triggering a request, waiting for that request to come, then signalling cancel, then immediately sending the next message, means that there's a high chance this will pass due to signal not being handled yet. However, waiting for the request after signalling cancel increases the likelihood that the cancel signal has been handled before we emit the next element, thereby increasing the likelihood that the test will actually test what it says its testing (that elements emitted after a cancel signal is handled won't cause an error).

Also could it be possible, and legal, that a request followed by a cancel is coalesced into just a cancel?

On a subscription, yes, that's legal and possible, but this isn't a subscription, this is the TCK puppet, and the TCK defines how implementations of the puppet are are to behave. It requires that the request signal does result in a request for demand to the subscription, regardless of what signal comes immediately after. And when these signals get forwarded onto the subscription, we know the subscription won't coalesce the signals because that is a subscription that the TCK has implemented itself in ManualPublisher, and it doesn't coalesce signals, it captures them all for assertions to be run later, assertions like expectRequest.

Copy link
Contributor

Choose a reason for hiding this comment

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

However, waiting for the request after signalling cancel increases the likelihood that the cancel signal has been handled before we emit the next element, thereby increasing the likelihood that the test will actually test what it says its testing (that elements emitted after a cancel signal is handled won't cause an error).

Since it is, as you say, not a full solution, may I suggest that it makes sense to add that as a comment, since it is non-apparent as to its intent?

Copy link

@jrudolph jrudolph May 28, 2019

Choose a reason for hiding this comment

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

On a subscription, yes, that's legal and possible, but this isn't a subscription, this is the TCK puppet, and the TCK defines how implementations of the puppet are are to behave. It requires that the request signal does result in a request for demand to the subscription, regardless of what signal comes immediately after. And when these signals get forwarded onto the subscription, we know the subscription won't coalesce the signals because that is a subscription that the TCK has implemented itself in ManualPublisher, and it doesn't coalesce signals, it captures them all for assertions to be run later, assertions like expectRequest.

These tests are also used in the IdentityProcessorVerification tests which implements the SubscriberPuppet as forwarding the triggers as is to the processor under test. So, IIUC the invariants you state would have to be valid for any identity processor implementation you might want to test. That would mean, that you cannot use the TCK to check processor implementations that do coalescing of requests and cancel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which case, perhaps we should change this to expectRequest before we signalCancel, and then insert a new expectCancelling after that, before we signalNext, to ensure that the subscriber did call cancel before we sent the next element - that's I think the original intent of the ordering of operations here, and matches the description of the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented this here: #462

@viktorklang
Copy link
Contributor

Nice work, @jroper!

@reactive-streams/contributors Yay or nay?

@viktorklang
Copy link
Contributor

@reactive-streams/contributors Merging this without objections.

@viktorklang viktorklang merged commit 0899761 into reactive-streams:master Dec 6, 2018
@viktorklang
Copy link
Contributor

Thanks @jroper! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants