Skip to content

Commit

Permalink
TestSubscription#requestedEquals(0) incorrectly validates the value (
Browse files Browse the repository at this point in the history
…#1642)

Motivation:

`TestSubscription#requestedEquals` depends on the passed `value` and if
`value == 0` it does not check the current cumulative value of requested
elements, it only checks if `request(long)` was ever invoked or not.

Modifications:

- Fix validation in `TestSubscription#requestedEquals`;
- Adjust existing tests to account for new behavior;

Result:

`TestSubscription#requestedEquals(0)` validates that `request(long)` was
invoked and the current cumulative value if equal to `0`.
  • Loading branch information
idelpivnitskiy authored and bondolo committed Jul 2, 2021
1 parent bae121c commit 8f2c372
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ void invalidThenValidRequest() {
@Test
void request0Propagated() {
subscriber.awaitSubscription().request(0);
triggerNextSubscribe();
assertThat("Invalid request-n not propagated " + subscription, subscription.requestedEquals(0),
triggerNextSubscribe(); // If subscribe happens after request(0) it will be mapped into -1
assertThat("Invalid request-n not propagated " + subscription, subscription.requestedEquals(-1),
is(true));
}

@Test
void request0PropagatedAfterComplete() {
source.onComplete();
triggerNextSubscribe();
subscriber.awaitSubscription().request(0);
next.onSubscribe(subscription);
assertThat("Invalid request-n not propagated " + subscription, subscription.requestedEquals(0),
is(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private void invalidThenValidRequest(long invalidN) {
void request0PropagatedAfterSuccess() {
source.onSuccess(1);
subscriber.awaitSubscription().request(1); // get the success from the Single
subscriber.awaitSubscription().request(0);
next.onSubscribe(subscription);
subscriber.awaitSubscription().request(0);
assertThat("Invalid request-n propagated " + subscription, subscription.requestedEquals(0),
is(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public long requested() {
* @return {@code true} if the cumulative value of {@link #request(long)} matches {@code value}.
*/
public boolean requestedEquals(long value) {
return value == 0 && requestCalled || value != 0 && requested.get() == value;
return (value != 0 || requestCalled) && requested.get() == value;
}

/**
Expand Down

0 comments on commit 8f2c372

Please sign in to comment.