Skip to content

Commit d6a683a

Browse files
committed
Fixed testNestedAsyncConcat not waiting for the parent to complete and
misses the last onComplete
1 parent b1a07b9 commit d6a683a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/test/java/io/reactivex/internal/operators/OperatorConcatTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ public void testSimpleAsyncConcat() {
131131

132132
@Test
133133
public void testNestedAsyncConcatLoop() throws Throwable {
134-
for (int i = 0; i < 100; i++) {
135-
System.out.println("testNestedAsyncConcat >> " + i);
134+
for (int i = 0; i < 500; i++) {
135+
if (i % 10 == 0) {
136+
System.out.println("testNestedAsyncConcat >> " + i);
137+
}
136138
testNestedAsyncConcat();
137139
}
138140
}
@@ -151,6 +153,9 @@ public void testNestedAsyncConcat() throws Throwable {
151153

152154
final AtomicReference<Thread> parent = new AtomicReference<>();
153155
final CountDownLatch parentHasStarted = new CountDownLatch(1);
156+
final CountDownLatch parentHasFinished = new CountDownLatch(1);
157+
158+
154159
Observable<Observable<String>> observableOfObservables = Observable.create(new Publisher<Observable<String>>() {
155160

156161
@Override
@@ -198,6 +203,7 @@ public void run() {
198203
} finally {
199204
System.out.println("Done parent Observable");
200205
observer.onComplete();
206+
parentHasFinished.countDown();
201207
}
202208
}
203209
}));
@@ -246,6 +252,15 @@ public void run() {
246252
throw new RuntimeException("failed waiting on threads", e);
247253
}
248254

255+
try {
256+
// wait for the parent to complete
257+
if (!parentHasFinished.await(5, TimeUnit.SECONDS)) {
258+
fail("Parent didn't finish within the time limit");
259+
}
260+
} catch (Throwable e) {
261+
throw new RuntimeException("failed waiting on threads", e);
262+
}
263+
249264
inOrder.verify(observer, times(1)).onNext("seven");
250265
inOrder.verify(observer, times(1)).onNext("eight");
251266
inOrder.verify(observer, times(1)).onNext("nine");

0 commit comments

Comments
 (0)