• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 @file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED", "DEPRECATION") // KT-21913
3 
4 package kotlinx.coroutines
5 
6 import kotlinx.coroutines.testing.*
7 import kotlin.test.*
8 
9 class DelayTest : TestBase() {
10 
11     @Test
testCancellationnull12     fun testCancellation() = runTest(expected = {it is CancellationException }) {
13         runAndCancel(1000)
14     }
15 
16     @Test
<lambda>null17     fun testMaxLongValue()= runTest(expected = {it is CancellationException }) {
18         runAndCancel(Long.MAX_VALUE)
19     }
20 
21     @Test
<lambda>null22     fun testMaxIntValue()= runTest(expected = {it is CancellationException }) {
23         runAndCancel(Int.MAX_VALUE.toLong())
24     }
25 
26     @Test
<lambda>null27     fun testRegularDelay() = runTest {
28         val deferred = async {
29             expect(2)
30             delay(1)
31             expect(3)
32         }
33 
34         expect(1)
35         yield()
36         deferred.await()
37         finish(4)
38     }
39 
<lambda>null40     private suspend fun runAndCancel(time: Long) = coroutineScope {
41         expect(1)
42         val deferred = async {
43             expect(2)
44             delay(time)
45             expectUnreached()
46         }
47 
48         yield()
49         expect(3)
50         require(deferred.isActive)
51         deferred.cancel()
52         finish(4)
53         deferred.await()
54     }
55 }
56