Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/schedulers/IoScheduledReleaseTest.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.schedulers;
15
16 import io.reactivex.rxjava3.core.Completable;
17 import io.reactivex.rxjava3.core.Flowable;
18 import io.reactivex.rxjava3.core.RxJavaTest;
19 import io.reactivex.rxjava3.schedulers.Schedulers;
20 import org.junit.Test;
21
22 import java.util.concurrent.TimeUnit;
23
24 public class IoScheduledReleaseTest extends RxJavaTest {
25
26 /* This test will be stuck in a deadlock if IoScheduler.USE_SCHEDULED_RELEASE is not set */
27 @Test
28 public void scheduledRelease() {
29 boolean savedScheduledRelease = IoScheduler.USE_SCHEDULED_RELEASE;
30 IoScheduler.USE_SCHEDULED_RELEASE = true;
31 try {
32 Flowable.just("item")
33 .observeOn(Schedulers.io())
34 .firstOrError()
35 .map(item -> {
36 for (int i = 0; i < 50; i++) {
37 Completable.complete()
38 .observeOn(Schedulers.io())
39 .blockingAwait();
40 }
41 return "Done";
42 })
43 .ignoreElement()
44 .test()
45 .awaitDone(5, TimeUnit.SECONDS)
46 .assertComplete();
47 } finally {
48 IoScheduler.USE_SCHEDULED_RELEASE = savedScheduledRelease;
49 }
50 }
51 }