blob: 67e59dca4afde2e8c8bf94a777c9b87abd752cca [file] [log] [blame]
Konrad Kamiński3ae898c2017-03-30 17:37:00 +02001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Konrad Kamiński3ae898c2017-03-30 17:37:00 +02003 */
4
5package kotlinx.coroutines.experimental.reactor
6
Roman Elizarovffc61ae2017-10-26 19:29:52 +03007import kotlinx.coroutines.experimental.*
Konrad Kamiński3ae898c2017-03-30 17:37:00 +02008import org.hamcrest.core.IsEqual
9import org.hamcrest.core.IsNot
10import org.junit.Assert.assertThat
Roman Elizarov45181042017-07-20 20:37:51 +030011import org.junit.Before
Konrad Kamiński3ae898c2017-03-30 17:37:00 +020012import org.junit.Test
13import reactor.core.scheduler.Schedulers
14
15class SchedulerTest : TestBase() {
Roman Elizarov45181042017-07-20 20:37:51 +030016 @Before
17 fun setup() {
18 ignoreLostThreads("single-")
19 }
20
Konrad Kamiński3ae898c2017-03-30 17:37:00 +020021 @Test
22 fun testSingleScheduler(): Unit = runBlocking {
23 expect(1)
24 val mainThread = Thread.currentThread()
Roman Elizarovf9e13f52017-12-21 12:23:15 +030025 withContext(Schedulers.single().asCoroutineDispatcher()) {
Konrad Kamiński3ae898c2017-03-30 17:37:00 +020026 val t1 = Thread.currentThread()
27 println(t1)
28 assertThat(t1, IsNot(IsEqual(mainThread)))
29 expect(2)
30 delay(100)
31 val t2 = Thread.currentThread()
32 println(t2)
33 assertThat(t2, IsNot(IsEqual(mainThread)))
34 expect(3)
35 }
36 finish(4)
37 }
38}