Roman Elizarov | a1fe3da | 2017-03-10 15:06:01 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2017 JetBrains s.r.o. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package kotlinx.coroutines.experimental.rx2 |
| 18 | |
| 19 | import io.reactivex.schedulers.Schedulers |
Roman Elizarov | ffc61ae | 2017-10-26 19:29:52 +0300 | [diff] [blame] | 20 | import kotlinx.coroutines.experimental.* |
Roman Elizarov | a1fe3da | 2017-03-10 15:06:01 +0300 | [diff] [blame] | 21 | import org.hamcrest.core.IsEqual |
| 22 | import org.hamcrest.core.IsNot |
| 23 | import org.junit.Assert.assertThat |
Roman Elizarov | 4518104 | 2017-07-20 20:37:51 +0300 | [diff] [blame] | 24 | import org.junit.Before |
Roman Elizarov | a1fe3da | 2017-03-10 15:06:01 +0300 | [diff] [blame] | 25 | import org.junit.Test |
| 26 | |
| 27 | class SchedulerTest : TestBase() { |
Roman Elizarov | 4518104 | 2017-07-20 20:37:51 +0300 | [diff] [blame] | 28 | @Before |
| 29 | fun setup() { |
| 30 | ignoreLostThreads("RxCachedThreadScheduler-", "RxCachedWorkerPoolEvictor-", "RxSchedulerPurge-") |
| 31 | } |
| 32 | |
Roman Elizarov | a1fe3da | 2017-03-10 15:06:01 +0300 | [diff] [blame] | 33 | @Test |
| 34 | fun testIoScheduler(): Unit = runBlocking { |
| 35 | expect(1) |
| 36 | val mainThread = Thread.currentThread() |
Roman Elizarov | f9e13f5 | 2017-12-21 12:23:15 +0300 | [diff] [blame] | 37 | withContext(Schedulers.io().asCoroutineDispatcher()) { |
Roman Elizarov | a1fe3da | 2017-03-10 15:06:01 +0300 | [diff] [blame] | 38 | val t1 = Thread.currentThread() |
| 39 | println(t1) |
| 40 | assertThat(t1, IsNot(IsEqual(mainThread))) |
| 41 | expect(2) |
| 42 | delay(100) |
| 43 | val t2 = Thread.currentThread() |
| 44 | println(t2) |
| 45 | assertThat(t2, IsNot(IsEqual(mainThread))) |
| 46 | expect(3) |
| 47 | } |
| 48 | finish(4) |
| 49 | } |
| 50 | } |