@@ -118,7 +118,7 @@ private MergeObservable(Observable<Observable<T>> sequences) {
118
118
this .sequences = sequences ;
119
119
}
120
120
121
- public MergeSubscription call (Observer <T > actualObserver ) {
121
+ public Subscription call (Observer <T > actualObserver ) {
122
122
123
123
/**
124
124
* We must synchronize a merge because we subscribe to multiple sequences in parallel that will each be emitting.
@@ -127,15 +127,16 @@ public MergeSubscription call(Observer<T> actualObserver) {
127
127
* <p>
128
128
* Bug report: https://github.com/Netflix/RxJava/issues/200
129
129
*/
130
- SynchronizedObserver <T > synchronizedObserver = new SynchronizedObserver <T >(actualObserver , new AtomicObservableSubscription (ourSubscription ));
130
+ AtomicObservableSubscription subscription = new AtomicObservableSubscription (ourSubscription );
131
+ SynchronizedObserver <T > synchronizedObserver = new SynchronizedObserver <T >(actualObserver , subscription );
131
132
132
133
/**
133
134
* Subscribe to the parent Observable to get to the children Observables
134
135
*/
135
136
sequences .subscribe (new ParentObserver (synchronizedObserver ));
136
137
137
138
/* return our subscription to allow unsubscribing */
138
- return ourSubscription ;
139
+ return subscription ;
139
140
}
140
141
141
142
/**
@@ -439,11 +440,13 @@ public void onNext(String v) {
439
440
// wait for both observables to send (one should be blocked)
440
441
o1 .onNextBeingSent .await ();
441
442
o2 .onNextBeingSent .await ();
442
-
443
- assertEquals (1 , concurrentCounter .get ());
444
443
445
- // release so it can finish
446
- endLatch .countDown ();
444
+ try { // in try/finally so threads are released via latch countDown even if assertion fails
445
+ assertEquals (1 , concurrentCounter .get ());
446
+ } finally {
447
+ // release so it can finish
448
+ endLatch .countDown ();
449
+ }
447
450
448
451
try {
449
452
o1 .t .join ();
0 commit comments