Skip to content

1.x: fix GroupBy delaying group completion till all groups were emitted #3787

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 1 commit into from
Mar 23, 2016
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
13 changes: 6 additions & 7 deletions src/main/java/rx/internal/operators/OperatorGroupBy.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ public void onCompleted() {
if (done) {
return;
}

for (GroupedUnicast<K, V> e : groups.values()) {
e.onComplete();
}
groups.clear();

done = true;
GROUP_COUNT.decrementAndGet(this);
drain();
Expand Down Expand Up @@ -328,13 +334,6 @@ boolean checkTerminated(boolean d, boolean empty,
return true;
} else
if (empty) {
List<GroupedUnicast<K, V>> list = new ArrayList<GroupedUnicast<K, V>>(groups.values());
groups.clear();

for (GroupedUnicast<K, V> e : list) {
e.onComplete();
}

actual.onCompleted();
return true;
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/rx/GroupByTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import rx.functions.Action1;
import rx.functions.Func1;
import rx.observables.GroupedObservable;
import rx.observers.TestSubscriber;

public class GroupByTests {

Expand Down Expand Up @@ -90,4 +91,27 @@ public void call(String v) {

System.out.println("**** finished");
}

@Test
public void groupsCompleteAsSoonAsMainCompletes() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Passed on 1.x without fix from this PR…

Copy link
Member Author

Choose a reason for hiding this comment

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

It fails on 1.1.1 and 1.1.2 but works on 1.1.0 and earlier for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I pulled master branch instead of 1.x (uh), confirm: it fails on 1.1.2.

TestSubscriber<Integer> ts = TestSubscriber.create();

Observable.range(0, 20)
.groupBy(new Func1<Integer, Integer>() {
@Override
public Integer call(Integer i) {
return i % 5;
}
})
.concatMap(new Func1<GroupedObservable<Integer, Integer>, Observable<Integer>>() {
@Override
public Observable<Integer> call(GroupedObservable<Integer, Integer> v) {
return v;
}
}).subscribe(ts);

ts.assertValues(0, 5, 10, 15, 1, 6, 11, 16, 2, 7, 12, 17, 3, 8, 13, 18, 4, 9, 14, 19);
ts.assertCompleted();
ts.assertNoErrors();
}
}