Skip to content

Commit ad5b16d

Browse files
committed
Add unit test for race in OperatorMaterialize
1 parent 03b0b37 commit ad5b16d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/test/java/rx/internal/operators/OperatorMaterializeTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
import rx.Notification;
3030
import rx.Observable;
3131
import rx.Subscriber;
32+
import rx.TestUtil;
33+
import rx.functions.Action0;
3234
import rx.functions.Action1;
3335
import rx.observers.TestSubscriber;
3436
import rx.schedulers.Schedulers;
37+
import rx.subjects.PublishSubject;
3538

3639
public class OperatorMaterializeTest {
3740

@@ -201,6 +204,33 @@ public void testUnsubscribeJustBeforeCompletionNotificationShouldPreventThatNoti
201204
ts.assertUnsubscribed();
202205
}
203206

207+
@Test
208+
public void testConcurrency() {
209+
for (int i = 0; i < 1000; i++) {
210+
final TestSubscriber<Notification<Integer>> ts = TestSubscriber.create(0);
211+
final PublishSubject<Integer> ps = PublishSubject.create();
212+
Action0 publishAction = new Action0() {
213+
@Override
214+
public void call() {
215+
ps.onCompleted();
216+
}
217+
};
218+
219+
Action0 requestAction = new Action0() {
220+
@Override
221+
public void call() {
222+
ts.requestMore(1);
223+
}
224+
};
225+
226+
ps.materialize().subscribe(ts);
227+
TestUtil.race(publishAction, requestAction);
228+
ts.assertValueCount(1);
229+
ts.assertTerminalEvent();
230+
ts.assertNoErrors();
231+
}
232+
}
233+
204234
private static class TestObserver extends Subscriber<Notification<String>> {
205235

206236
boolean onCompleted;

0 commit comments

Comments
 (0)