blob: fe3c71a8041341bfb6f2372fa7b31755f44cc803 [file] [log] [blame]
Roman Elizarovf5e67ba2018-08-23 17:27:19 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Roman Elizarov0950dfa2018-07-13 10:33:25 +03005package kotlinx.coroutines
Roman Elizarov8fecc202018-09-05 22:07:41 +03006
Roman Elizarovf5e67ba2018-08-23 17:27:19 +03007import org.junit.Test
8import kotlin.test.*
9
10class 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 Elizarovdc29b072018-09-11 18:42:03 +030016 withContext(Dispatchers.IO) {
Roman Elizarovf5e67ba2018-08-23 17:27:19 +030017 expect(2)
18 assertNotSame(mainThread, Thread.currentThread())
19 }
Roman Elizarov0950dfa2018-07-13 10:33:25 +030020
Roman Elizarovf5e67ba2018-08-23 17:27:19 +030021 expect(3)
22 assertSame(mainThread, Thread.currentThread())
23 finish(4)
24 }
25}