Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental.reactor |
| 6 | |
Roman Elizarov | ffc61ae | 2017-10-26 19:29:52 +0300 | [diff] [blame] | 7 | import kotlinx.coroutines.experimental.* |
Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 8 | import org.hamcrest.core.IsEqual |
| 9 | import org.hamcrest.core.IsNot |
| 10 | import org.junit.Assert.assertThat |
Roman Elizarov | 4518104 | 2017-07-20 20:37:51 +0300 | [diff] [blame] | 11 | import org.junit.Before |
Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 12 | import org.junit.Test |
| 13 | import reactor.core.scheduler.Schedulers |
| 14 | |
| 15 | class SchedulerTest : TestBase() { |
Roman Elizarov | 4518104 | 2017-07-20 20:37:51 +0300 | [diff] [blame] | 16 | @Before |
| 17 | fun setup() { |
| 18 | ignoreLostThreads("single-") |
| 19 | } |
| 20 | |
Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 21 | @Test |
| 22 | fun testSingleScheduler(): Unit = runBlocking { |
| 23 | expect(1) |
| 24 | val mainThread = Thread.currentThread() |
Roman Elizarov | f9e13f5 | 2017-12-21 12:23:15 +0300 | [diff] [blame] | 25 | withContext(Schedulers.single().asCoroutineDispatcher()) { |
Konrad Kamiński | 3ae898c | 2017-03-30 17:37:00 +0200 | [diff] [blame] | 26 | 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 | } |