blob: 13bb66d9b61c23e4c0415d838cb07506c824b670 [file] [log] [blame]
Konrad Kamiński5d273a92017-04-26 17:18:41 +02001/*
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.rx1
18
Roman Elizarovffc61ae2017-10-26 19:29:52 +030019import kotlinx.coroutines.experimental.*
Konrad Kamiński5d273a92017-04-26 17:18:41 +020020import org.hamcrest.core.IsEqual
21import org.hamcrest.core.IsNot
22import org.junit.Assert.assertThat
Roman Elizarov45181042017-07-20 20:37:51 +030023import org.junit.Before
Konrad Kamiński5d273a92017-04-26 17:18:41 +020024import org.junit.Test
25import rx.schedulers.Schedulers
26
27class SchedulerTest : TestBase() {
Roman Elizarov45181042017-07-20 20:37:51 +030028 @Before
29 fun setup() {
30 ignoreLostThreads("RxIoScheduler-")
31 }
32
Konrad Kamiński5d273a92017-04-26 17:18:41 +020033 @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()) {
Konrad Kamiński5d273a92017-04-26 17:18:41 +020038 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}