/
ConfigTestSuite.kt
62 lines (49 loc) · 1.46 KB
/
ConfigTestSuite.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.server.testing.suites
import io.ktor.server.engine.*
import kotlinx.coroutines.*
import org.junit.*
import org.junit.Assert.*
import java.util.concurrent.*
import kotlin.system.*
var count = 0
abstract class ConfigTestSuite(val engine: ApplicationEngineFactory<*, *>) {
@Test
fun testStartOnceWhenException() {
// Please note that it's critical to not capture any variables inside the scope
// It will disable autoreload and change behaviour
val server = embeddedServer(engine) {
count++
error("Foo")
}
assertFailsWith<IllegalStateException> {
server.start()
}
assertEquals(1, count)
server.stop(1, 1, TimeUnit.SECONDS)
}
@Test
fun testStartsOnceWithCapture() {
var counter = 0
val server = embeddedServer(engine) {
counter++
error("Foo")
}
assertFailsWith<IllegalStateException> {
server.start()
}
assertEquals(1, counter)
server.stop(1, 1, TimeUnit.SECONDS)
}
@Test
fun testFastStop() = runBlocking {
val server = embeddedServer(engine) {
}
val time = measureTimeMillis {
server.stop(0, 100, TimeUnit.SECONDS)
}
assertTrue("Stop time is $time", time < 100)
}
}