Skip to content
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

2.x: Coverage improvements, logical fixes and cleanups 03/08 #5905

Merged
merged 1 commit into from
Mar 9, 2018

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Mar 9, 2018

This PR fixes a couple of logical errors and cleans up some other components as well as improves the coverage of some classes. See the change comments below about the relevant details.

t.onSubscribe(rp);

boolean doReplay = true;
Copy link
Member Author

Choose a reason for hiding this comment

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

The old logic could have made the Subscriber visible too early and thus it could receive an onComplete before an onSubscribe.

return;
}
}
BackpressureHelper.addCancel(requested, n);
Copy link
Member Author

Choose a reason for hiding this comment

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

Use the helper that was not available the time this class was developed.


while (j < s && r > 0) {
while (j < s && e != r) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Use the now more modern emitted-requested tracking pairs.

@@ -364,15 +370,12 @@ public void replay() {
}
}

if (valuesProduced != 0) {
BackpressureHelper.producedCancel(rq, valuesProduced);
Copy link
Member Author

Choose a reason for hiding this comment

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

Having a separate emitted, there is no need to decrement the requested amount, saving on an atomic instruction.

return queue.isEmpty();
}
return !it.hasNext();
return current == null && queue.isEmpty();
Copy link
Member Author

Choose a reason for hiding this comment

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

An iterator is always checked for hasNext before the control is given back in poll and current is always null if the previous iterator had no further elements. Therefore, the in the original code !it.hasNext() was always false.

@@ -1215,7 +1215,8 @@ public void subscribe(Subscriber<? super T> child) {
buf = bufferFactory.call();
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
throw ExceptionHelper.wrapOrThrow(ex);
EmptySubscription.error(ex, child);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a subscribe implementation which should not crash but signal the problem to the Subscriber.

InnerDisposable[] ps = observers.getAndSet(TERMINATED);
if (ps != TERMINATED) {
current.compareAndSet(PublishObserver.this, null);
InnerDisposable[] ps = observers.getAndSet(TERMINATED);
Copy link
Member Author

Choose a reason for hiding this comment

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

Bias the dispose logic towards a more likely single disposal.

@akarnokd
Copy link
Member Author

akarnokd commented Mar 9, 2018

Changes explained.

@codecov
Copy link

codecov bot commented Mar 9, 2018

Codecov Report

Merging #5905 into 2.x will increase coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5905      +/-   ##
============================================
+ Coverage     97.92%   98.05%   +0.12%     
- Complexity     5987     5995       +8     
============================================
  Files           655      655              
  Lines         43925    43920       -5     
  Branches       6087     6085       -2     
============================================
+ Hits          43014    43065      +51     
+ Misses          281      253      -28     
+ Partials        630      602      -28
Impacted Files Coverage Δ Complexity Δ
...ex/internal/operators/flowable/FlowableReplay.java 94.08% <100%> (+1.49%) 23 <0> (+1) ⬆️
...al/operators/flowable/FlowableFlattenIterable.java 100% <100%> (+2.75%) 4 <0> (ø) ⬇️
...vex/internal/operators/flowable/FlowableCache.java 98.63% <100%> (+5.38%) 11 <0> (+4) ⬆️
...ternal/operators/observable/ObservablePublish.java 100% <100%> (+3.5%) 11 <0> (ø) ⬇️
...a/io/reactivex/internal/util/QueueDrainHelper.java 95.83% <0%> (-2.78%) 55% <0%> (-2%)
...nternal/operators/parallel/ParallelReduceFull.java 93.06% <0%> (-1.99%) 2% <0%> (ø)
...internal/operators/observable/ObservableCache.java 93.7% <0%> (-1.58%) 9% <0%> (ø)
...rnal/subscriptions/DeferredScalarSubscription.java 98.46% <0%> (-1.54%) 28% <0%> (-1%)
...ternal/operators/observable/ObservableFlatMap.java 86.58% <0%> (-1.28%) 3% <0%> (ø)
...ernal/operators/flowable/FlowableFlatMapMaybe.java 92.27% <0%> (-0.97%) 2% <0%> (ø)
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e5d5a2...ef037e1. Read the comment docs.

Copy link
Collaborator

@vanniktech vanniktech left a comment

Choose a reason for hiding this comment

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

Congrats on the 98%

for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final Flowable<Integer> cache = Flowable.range(1, 500).cache();

final TestSubscriber<Integer> to1 = new TestSubscriber<Integer>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

ts1

Copy link
Member Author

Choose a reason for hiding this comment

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

There are at least 178 such unrenamed local variables. I'll post a separate PR fixing all of them and perhaps add a validator unit test that looks for this very common mistake.

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.

2 participants