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
88 changes: 88 additions & 0 deletions src/test/java/io/reactivex/rxjava4/core/XFlatMapIsolatedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/

package io.reactivex.rxjava4.core;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Flow.Publisher;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;

import io.reactivex.rxjava4.exceptions.TestException;
import io.reactivex.rxjava4.functions.Function;
import io.reactivex.rxjava4.plugins.RxJavaPlugins;
import io.reactivex.rxjava4.schedulers.Schedulers;
import io.reactivex.rxjava4.subscribers.TestSubscriber;
import io.reactivex.rxjava4.testsupport.TestHelper;

@Isolated
public class XFlatMapIsolatedTest extends RxJavaTest {

static final int SLEEP_AFTER_CANCEL = 500;

final CyclicBarrier cb = new CyclicBarrier(2);

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(TestSubscriber<?> ts) throws Exception {
long before = System.currentTimeMillis();
Thread.sleep(50);
if (System.currentTimeMillis() - before > 100) {
ts.cancel();
throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before));
}
}

@Test
public void singlePublisher() throws Exception {
withRetry(3, () -> {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Single.just(1)
.subscribeOn(Schedulers.cached())
.flatMapPublisher((Function<Integer, Publisher<Integer>>) _ -> {
sleep();
return Flowable.<Integer>error(new TestException());
})
.test();

cb.await();

beforeCancelSleep(ts);

ts.cancel();

Thread.sleep(SLEEP_AFTER_CANCEL);

ts.assertEmpty();

assertTrue(errors.isEmpty(), errors.toString());
} finally {
RxJavaPlugins.reset();
}
});
}
}
30 changes: 0 additions & 30 deletions src/test/java/io/reactivex/rxjava4/core/XFlatMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,36 +487,6 @@ public void singleCompletable2() throws Exception {
});
}

@Test
public void singlePublisher() throws Exception {
withRetry(3, () -> {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Single.just(1)
.subscribeOn(Schedulers.cached())
.flatMapPublisher((Function<Integer, Publisher<Integer>>) _ -> {
sleep();
return Flowable.<Integer>error(new TestException());
})
.test();

cb.await();

beforeCancelSleep(ts);

ts.cancel();

Thread.sleep(SLEEP_AFTER_CANCEL);

ts.assertEmpty();

assertTrue(errors.isEmpty(), errors.toString());
} finally {
RxJavaPlugins.reset();
}
});
}

@Test
public void singleCombiner() throws Exception {
withRetry(3, () -> {
Expand Down
Loading