Skip to content

Cancel the subscription after receiving all of the pertinent emissions (#259) #260

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
Apr 8, 2015
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 @@ -1044,6 +1044,8 @@ public void onNext(T element) {
if (callsCounter > 0) {
subscription.value().request(Long.MAX_VALUE - 1);
callsCounter--;
} else {
subscription.value().cancel();
}
} else {
env.flop(String.format("Subscriber::onNext(%s) called before Subscriber::onSubscribe", element));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.reactivestreams.Subscription;
import org.reactivestreams.tck.support.TCKVerificationSupport;
import org.reactivestreams.tck.support.TestException;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Random;
Expand Down Expand Up @@ -585,6 +586,38 @@ public void required_spec317_mustSupportACumulativePendingElementCountUpToLongMa
}, "Async error during test execution: Illegally signalling onError too soon!");
}

@Test
public void required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue_forSynchronousPublisher() throws Throwable {
final AtomicInteger sent = new AtomicInteger();

customPublisherVerification(new Publisher<Integer>() {
@Override
public void subscribe(final Subscriber<? super Integer> downstream) {
downstream.onSubscribe(new Subscription() {
boolean started;
boolean cancelled;

@Override
public void request(long n) {
if (!started) {
started = true;
while (!cancelled) {
downstream.onNext(sent.getAndIncrement());
}
}
}

@Override
public void cancel() {
cancelled = true;
}
});
}
}).required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue();

// 11 due to the implementation of this particular TCK test (see impl)
Assert.assertEquals(sent.get(), 11);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd skip this check, the test "passes" if it doesn't end up infinitely publishing - it's true that it is 11 signals but I wouldn't test for this number.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's the verification test, isn't it fine to be specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong feelings about it, can stay as is :)

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is wrong I'd want to see it removed, but from a cursory inspection I don't see that it could be problematic, but if I am wrong, please do tell me!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's definitely not wrong, just depending on the internally+arbitrarily chosen value inside of required_spec317_mustNotSignalOnErrorWhenPendingAboveLongMaxValue.

You're right though that these are very specific tests so keeping as-is may be a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we change the underlying TCK impl then we'd also have to change this assertion, I think that's good.

}

// FAILING IMPLEMENTATIONS //

Expand Down