Roman Elizarov | f5e67ba | 2018-08-23 17:27:19 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 5 | package kotlinx.coroutines |
Roman Elizarov | 8fecc20 | 2018-09-05 22:07:41 +0300 | [diff] [blame] | 6 | |
Roman Elizarov | f5e67ba | 2018-08-23 17:27:19 +0300 | [diff] [blame] | 7 | import org.junit.Test |
| 8 | import kotlin.test.* |
| 9 | |
| 10 | class IODispatcherTest : TestBase() { |
| 11 | @Test |
| 12 | fun testWithIOContext() = runTest { |
| 13 | // just a very basic test that is dispatcher works and indeed uses background thread |
| 14 | val mainThread = Thread.currentThread() |
| 15 | expect(1) |
Roman Elizarov | dc29b07 | 2018-09-11 18:42:03 +0300 | [diff] [blame] | 16 | withContext(Dispatchers.IO) { |
Roman Elizarov | f5e67ba | 2018-08-23 17:27:19 +0300 | [diff] [blame] | 17 | expect(2) |
| 18 | assertNotSame(mainThread, Thread.currentThread()) |
| 19 | } |
Roman Elizarov | 0950dfa | 2018-07-13 10:33:25 +0300 | [diff] [blame] | 20 | |
Roman Elizarov | f5e67ba | 2018-08-23 17:27:19 +0300 | [diff] [blame] | 21 | expect(3) |
| 22 | assertSame(mainThread, Thread.currentThread()) |
| 23 | finish(4) |
| 24 | } |
| 25 | } |