forked from kotlin-hands-on/intro-coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequest8RxKtTest.kt
36 lines (29 loc) · 1.21 KB
/
Request8RxKtTest.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
package tasks
import contributors.MockGithubService
import contributors.expectedConcurrentResults
import contributors.testRequestData
import contributors.testScheduler
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.util.concurrent.TimeUnit
internal class Request8RxKtTest {
@Before
fun setUp() {
testScheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS)
}
@Test
fun loadContributorsReactive() {
val testObserver = loadContributorsReactive(MockGithubService, testRequestData, testScheduler).test()
testObserver.assertNoValues()
val startTime = testScheduler.now(TimeUnit.MILLISECONDS)
testScheduler.advanceTimeBy(expectedConcurrentResults.timeFromStart, TimeUnit.MILLISECONDS)
testObserver.assertValue(expectedConcurrentResults.users)
val totalTime = testScheduler.now(TimeUnit.MILLISECONDS) - startTime
Assert.assertEquals(
"The calls run concurrently, so the total virtual time should be 2200 ms: " +
"1000 ms for repos request plus max(1000, 1200, 800) = 1200 ms for concurrent contributors requests)",
expectedConcurrentResults.timeFromStart, totalTime
)
}
}