Skip to content

2.x: attempt to fix a few time-sensitive tests. #5421

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

Merged
merged 2 commits into from
Jun 16, 2017
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
51 changes: 31 additions & 20 deletions src/test/java/io/reactivex/XFlatMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

import io.reactivex.exceptions.TestException;
import io.reactivex.functions.Function;
import io.reactivex.observers.TestObserver;
import io.reactivex.observers.*;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.TestSubscriber;

public class XFlatMapTest {

@Rule
public Retry retry = new Retry(3, 1000, true);
public Retry retry = new Retry(5, 1000, true);

static final int SLEEP_AFTER_CANCEL = 500;

Expand All @@ -40,12 +40,23 @@ public class XFlatMapTest {
void sleep() throws Exception {
cb.await();
try {
long before = System.currentTimeMillis();
Thread.sleep(5000);
throw new IllegalStateException("Was not interrupted in time?! " + (System.currentTimeMillis() - before));
} catch (InterruptedException ex) {
// ignored here
}
}

void beforeCancelSleep(BaseTestConsumer<?, ?> ts) throws Exception {
long before = System.currentTimeMillis();
Thread.sleep(50);
if (System.currentTimeMillis() - before > 100) {
ts.dispose();
throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before));
}
}

@Test
public void flowableFlowable() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
Expand All @@ -63,7 +74,7 @@ public Publisher<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -94,7 +105,7 @@ public Single<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -125,7 +136,7 @@ public Maybe<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -156,7 +167,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -188,7 +199,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -219,7 +230,7 @@ public Observable<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -250,7 +261,7 @@ public Single<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -281,7 +292,7 @@ public Maybe<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -312,7 +323,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -344,7 +355,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -375,7 +386,7 @@ public Single<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -406,7 +417,7 @@ public Maybe<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -437,7 +448,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -469,7 +480,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -500,7 +511,7 @@ public Single<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -531,7 +542,7 @@ public Maybe<Integer> apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -562,7 +573,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down Expand Up @@ -594,7 +605,7 @@ public Completable apply(Integer v) throws Exception {

cb.await();

Thread.sleep(50);
beforeCancelSleep(ts);

ts.cancel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void testSimpleAsyncLoop() {
}
}
}
@Test(timeout = 10000)
@Test(timeout = 30000)
public void testSimpleAsync() {
for (int i = 1; i < 50; i++) {
TestObserver<Integer> ts = new TestObserver<Integer>();
Expand All @@ -221,13 +221,13 @@ public void testSimpleAsync() {
assertEquals(expected, actual);
}
}
@Test(timeout = 10000)
@Test(timeout = 30000)
public void testSimpleOneLessAsyncLoop() {
for (int i = 0; i < 200; i++) {
testSimpleOneLessAsync();
}
}
@Test(timeout = 10000)
@Test(timeout = 30000)
public void testSimpleOneLessAsync() {
long t = System.currentTimeMillis();
for (int i = 2; i < 50; i++) {
Expand Down