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: fix Single.timeout unnecessary dispose calls #5586

Merged
merged 2 commits into from
Sep 10, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Route to RxJavaPlugins.onError
akarnokd committed Sep 10, 2017
commit 75b425d0d635f2517725280483e7fbf7a7d30ef5
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import io.reactivex.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.plugins.RxJavaPlugins;

public final class SingleTimeout<T> extends Single<T> {

@@ -139,6 +140,8 @@ public void onError(Throwable e) {
if (d != DisposableHelper.DISPOSED && compareAndSet(d, DisposableHelper.DISPOSED)) {
DisposableHelper.dispose(task);
actual.onError(e);
} else {
RxJavaPlugins.onError(e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we deliver error to RxJavaPlugins.onError() in else block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Fixed.

}

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@

import static org.junit.Assert.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
@@ -23,6 +24,7 @@
import io.reactivex.exceptions.TestException;
import io.reactivex.functions.Action;
import io.reactivex.observers.TestObserver;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.TestScheduler;
import io.reactivex.subjects.*;

@@ -167,36 +169,44 @@ public void run() {
@Test
public void errorTimeoutRace() {
final TestException ex = new TestException();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {

for (int i = 0; i < 1000; i++) {
final SingleSubject<Integer> subj = SingleSubject.create();
SingleSubject<Integer> fallback = SingleSubject.create();
for (int i = 0; i < 1000; i++) {
final SingleSubject<Integer> subj = SingleSubject.create();
SingleSubject<Integer> fallback = SingleSubject.create();

final TestScheduler sch = new TestScheduler();
final TestScheduler sch = new TestScheduler();

TestObserver<Integer> to = subj.timeout(1, TimeUnit.MILLISECONDS, sch, fallback).test();
TestObserver<Integer> to = subj.timeout(1, TimeUnit.MILLISECONDS, sch, fallback).test();

Runnable r1 = new Runnable() {
@Override
public void run() {
subj.onError(ex);
}
};
Runnable r1 = new Runnable() {
@Override
public void run() {
subj.onError(ex);
}
};

Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
}
};

TestHelper.race(r1, r2);
TestHelper.race(r1, r2);

if (!fallback.hasObservers()) {
to.assertFailure(TestException.class);
} else {
to.assertEmpty();
if (!fallback.hasObservers()) {
to.assertFailure(TestException.class);
} else {
to.assertEmpty();
}
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
}
} finally {
RxJavaPlugins.reset();
}
}
}