Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public void onSubscribe(Subscription s) {

@Override
public void onNext(T t) {
value.add(t);
U v = value;
if (v != null) {
v.add(t);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package io.reactivex.internal.operators.flowable;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.util.*;
Expand All @@ -23,7 +24,6 @@
import org.reactivestreams.Subscriber;

import io.reactivex.*;
import io.reactivex.Flowable;
import io.reactivex.exceptions.TestException;
import io.reactivex.observers.TestObserver;
import io.reactivex.processors.PublishProcessor;
Expand Down Expand Up @@ -389,4 +389,83 @@ public Collection<Integer> call() throws Exception {
.assertFailure(NullPointerException.class)
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
}

@Test
public void onNextCancelRace() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestObserver<List<Integer>> ts = pp.toList().test();

Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);
}

}

@Test
public void onNextCancelRaceFlowable() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestSubscriber<List<Integer>> ts = pp.toList().toFlowable().test();

Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);
}

}

@Test
public void onCompleteCancelRaceFlowable() {
for (int i = 0; i < 1000; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final TestSubscriber<List<Integer>> ts = pp.toList().toFlowable().test();

pp.onNext(1);

Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onComplete();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
ts.cancel();
}
};

TestHelper.race(r1, r2);

if (ts.valueCount() != 0) {
ts.assertValue(Arrays.asList(1))
.assertNoErrors();
}
}

}
}