blob: 9d3b8cdc2c83d7257ccdf5da5080b821a94a47e4 [file] [log] [blame]
Roman Elizarova1fe3da2017-03-10 15:06:01 +03001/*
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
17package kotlinx.coroutines.experimental.rx2
18
19import io.reactivex.schedulers.Schedulers
Roman Elizarovffc61ae2017-10-26 19:29:52 +030020import kotlinx.coroutines.experimental.*
Roman Elizarova1fe3da2017-03-10 15:06:01 +030021import org.hamcrest.core.IsEqual
22import org.hamcrest.core.IsNot
23import org.junit.Assert.assertThat
Roman Elizarov45181042017-07-20 20:37:51 +030024import org.junit.Before
Roman Elizarova1fe3da2017-03-10 15:06:01 +030025import org.junit.Test
26
27class SchedulerTest : TestBase() {
Roman Elizarov45181042017-07-20 20:37:51 +030028 @Before
29 fun setup() {
30 ignoreLostThreads("RxCachedThreadScheduler-", "RxCachedWorkerPoolEvictor-", "RxSchedulerPurge-")
31 }
32
Roman Elizarova1fe3da2017-03-10 15:06:01 +030033 @Test
34 fun testIoScheduler(): Unit = runBlocking {
35 expect(1)
36 val mainThread = Thread.currentThread()
Roman Elizarovf9e13f52017-12-21 12:23:15 +030037 withContext(Schedulers.io().asCoroutineDispatcher()) {
Roman Elizarova1fe3da2017-03-10 15:06:01 +030038 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}