-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoApplicationTests.kt
53 lines (42 loc) · 1.16 KB
/
DemoApplicationTests.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
package com.example.demo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class DemoApplicationTests {
@Autowired
lateinit var repository: UserRepository
@AfterEach
fun cleanUpDb() {
repository.deleteAll()
}
@Test
fun `should handle 10 queries at the same time`() {
val inserted = repository.save(UserEntity(0, "username", emails = setOf(UserEmailAddress("[email protected]"))))
val id = inserted.userId
runBlocking(Dispatchers.IO) {
(0 until 10).map {
async {
repository.findByUserId(id)
}
}.awaitAll()
}
}
@Test
fun `should handle 9 queries at the same time`() {
val inserted = repository.save(UserEntity(0, "username", emails = setOf(UserEmailAddress("[email protected]"))))
val id = inserted.userId
runBlocking(Dispatchers.IO) {
(0 until 9).map {
async {
repository.findByUserId(id)
}
}.awaitAll()
}
}
}