Skip to content

Commit 5b5aade

Browse files
Make Materialize.testMultipleSubscribes test deterministic
Refactored to use BlockingObservable instead of non-blocking subscribe and waiting on the underlying thread (it was only waiting on one of two threads running). This should resolve one of the issues reported in http://github.com/Netflix/RxJava/issues/329
1 parent 1cc2f6a commit 5b5aade

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

rxjava-core/src/main/java/rx/operators/OperationMaterialize.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.List;
2121
import java.util.Vector;
22+
import java.util.concurrent.ExecutionException;
2223

2324
import org.junit.Test;
2425

@@ -139,25 +140,13 @@ public void testMaterialize2() {
139140
}
140141

141142
@Test
142-
public void testMultipleSubscribes() {
143-
final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three");
144-
145-
Observable<Notification<String>> m = Observable.create(materialize(o1));
146-
147-
TestObserver Observer1 = new TestObserver();
148-
m.subscribe(Observer1);
149-
150-
TestObserver Observer2 = new TestObserver();
151-
m.subscribe(Observer2);
143+
public void testMultipleSubscribes() throws InterruptedException, ExecutionException {
144+
final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three");
152145

153-
try {
154-
o1.t.join();
155-
} catch (InterruptedException e) {
156-
throw new RuntimeException(e);
157-
}
146+
Observable<Notification<String>> m = Observable.create(materialize(o));
158147

159-
assertEquals(3, Observer1.notifications.size());
160-
assertEquals(3, Observer2.notifications.size());
148+
assertEquals(3, m.toList().toBlockingObservable().toFuture().get().size());
149+
assertEquals(3, m.toList().toBlockingObservable().toFuture().get().size());
161150
}
162151

163152
}
@@ -193,7 +182,7 @@ private static class TestAsyncErrorObservable extends Observable<String> {
193182
valuesToReturn = values;
194183
}
195184

196-
Thread t;
185+
volatile Thread t;
197186

198187
@Override
199188
public Subscription subscribe(final Observer<String> observer) {

0 commit comments

Comments
 (0)