Skip to content

Fix missing cancel() in tests that don't consume the entire source #346

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
May 3, 2017

Conversation

akarnokd
Copy link
Contributor

Some of the PublisherVerification tests didn't cancel the Subscription when they stopped consuming the source.

2.6: A Subscriber MUST call Subscription.cancel() if it is no longer valid to the Publisher without the Publisher having signaled onError or onComplete.
💡 The intent of this rule is to establish that Subscribers cannot just throw Subscriptions away when they are no longer needed, they have to call cancel so that resources held by that Subscription can be safely, and timely, reclaimed.

@akarnokd akarnokd changed the title Fix missing cancel() from in tests that don't consume the entire source Fix missing cancel() in tests that don't consume the entire source Mar 14, 2017
sub.expectNone(String.format("Publisher %sproduced unrequested ", pub));
} finally {
sub.cancel();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

good

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

});
onSubscribeLatch.expectClose("Should have received onSubscribe");
env.verifyNoAsyncErrorsNoDelay();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

good

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

if (fail) {
throw new AssertionError("Cancellations were missing:" + b);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Useful, thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work, @akarnokd!

}

public RangePublisherTest() {
super(new TestEnvironment(25));
Copy link
Contributor

@ktoso ktoso Mar 14, 2017

Choose a reason for hiding this comment

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

the default one should be fine, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use 25 ms for most of the synchronous tests in RxJava because otherwise it takes minutes to work through the 100+ TCK tests. Since this Publisher is synchronous, there is little to no chance for a timeout in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't the Rx suite nor does it impact the Rx suite, so that does not really matter :-)

It does, however, break the configurability of the timeouts for how we use them in this repo: since the setting is given via env value: https://github.com/reactive-streams/reactive-streams-jvm/blob/master/.travis.yml#L14 and settings in code win over settings from env (documented here: https://github.com/reactive-streams/reactive-streams-jvm/tree/master/tck#timeout-configuration ).

Please note that timeout does not hurt suite time all that much, the more painful one is (as explained here: https://github.com/reactive-streams/reactive-streams-jvm/tree/master/tck#timeout-configuration
) contributes much more to "actually waiting doing nothing time", so if anything the other one is more influential AFAIR.

Please stick to the default here so the .travis.yml configuration continues to work in the project, thanks.

@ktoso
Copy link
Contributor

ktoso commented Mar 14, 2017

TCK fixes look correct, thanks for catching this.

@akarnokd
Copy link
Contributor Author

Updated to default TestEnvironment().

@smaldini
Copy link
Contributor

:+1

s.onSubscribe(parent);
}

static final class RangeSubscription extends AtomicLong implements Subscription {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be of greater utility to have it be an IteratorSubscription?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main purpose was to track cancellation/completion in response to the TCK and this was the simplest multi-valued Publisher I could think of.

Working with an iterator requires a lot of try-catches around the method calls to Iterator because they may throw (for example, I saw libraries that hid JDBC calls behind plain iterators).

Copy link
Contributor

Choose a reason for hiding this comment

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

@akarnokd Fair enough, we can leave that to another time. :)

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 guess you meant an example IteratorSubscription. How about I post a PR to the examples submodule with a few basic subscription types?

Copy link
Contributor

Choose a reason for hiding this comment

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

@akarnokd No, not an example. I thought it might be iteresting for the TCK to have a sync publisher which can be supplied an Iterable :)

@ktoso
Copy link
Contributor

ktoso commented Mar 25, 2017

In case my previous comment was not clear enough: LGTM, thanks 😉

@smaldini
Copy link
Contributor

@reactive-streams/contributors let me know if we can merge (or add approved in review menu)

@viktorklang
Copy link
Contributor

@reactive-streams/contributors Ok, merging.

@viktorklang viktorklang merged commit 3f8a79b into reactive-streams:master May 3, 2017
@viktorklang viktorklang added this to the 1.0.1 milestone May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants