|
31 | 31 | import rx.Observable.OnSubscribe; |
32 | 32 | import rx.Observer; |
33 | 33 | import rx.Subscriber; |
| 34 | +import rx.observers.TestSubscriber; |
34 | 35 | import rx.schedulers.Schedulers; |
35 | 36 | import rx.subjects.PublishSubject; |
36 | 37 | import rx.subscriptions.Subscriptions; |
@@ -334,26 +335,31 @@ public void testTimeoutSelectorWithTimeoutAndOnNextRaceCondition() throws Interr |
334 | 335 | public Observable<Integer> call(Integer t1) { |
335 | 336 | if (t1 == 1) { |
336 | 337 | // Force "unsubscribe" run on another thread |
337 | | - return Observable.create(new OnSubscribe<Integer>(){ |
| 338 | + return Observable.create(new OnSubscribe<Integer>() { |
338 | 339 | @Override |
339 | 340 | public void call(Subscriber<? super Integer> subscriber) { |
340 | | - subscriber.add(Subscriptions.create(new Action0(){ |
| 341 | + subscriber.add(Subscriptions.create(new Action0() { |
341 | 342 | @Override |
342 | 343 | public void call() { |
343 | 344 | try { |
344 | 345 | // emulate "unsubscribe" is busy and finishes after timeout.onNext(1) |
345 | 346 | timeoutEmittedOne.await(); |
346 | 347 | } catch (InterruptedException e) { |
| 348 | + // if we are interrupted then we complete (as this can happen when unsubscribed) |
| 349 | + observerCompleted.countDown(); |
347 | 350 | e.printStackTrace(); |
348 | 351 | } |
349 | | - }})); |
| 352 | + } |
| 353 | + })); |
350 | 354 | // force the timeout message be sent after observer.onNext(2) |
351 | 355 | try { |
352 | 356 | observerReceivedTwo.await(); |
353 | 357 | } catch (InterruptedException e) { |
| 358 | + // if we are interrupted then we complete (as this can happen when unsubscribed) |
| 359 | + observerCompleted.countDown(); |
354 | 360 | e.printStackTrace(); |
355 | 361 | } |
356 | | - if(!subscriber.isUnsubscribed()) { |
| 362 | + if (!subscriber.isUnsubscribed()) { |
357 | 363 | subscriber.onNext(1); |
358 | 364 | timeoutEmittedOne.countDown(); |
359 | 365 | } |
@@ -386,12 +392,14 @@ public Void answer(InvocationOnMock invocation) throws Throwable { |
386 | 392 |
|
387 | 393 | }).when(o).onCompleted(); |
388 | 394 |
|
| 395 | + final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(o); |
| 396 | + |
389 | 397 | new Thread(new Runnable() { |
390 | 398 |
|
391 | 399 | @Override |
392 | 400 | public void run() { |
393 | 401 | PublishSubject<Integer> source = PublishSubject.create(); |
394 | | - source.timeout(timeoutFunc, Observable.from(3)).subscribe(o); |
| 402 | + source.timeout(timeoutFunc, Observable.from(3)).subscribe(ts); |
395 | 403 | source.onNext(1); // start timeout |
396 | 404 | source.onNext(2); // disable timeout |
397 | 405 | try { |
|
0 commit comments