diff --git a/test/tasks/Request4SuspendKtTest.kt b/test/tasks/Request4SuspendKtTest.kt index af92edb..a343a5c 100644 --- a/test/tasks/Request4SuspendKtTest.kt +++ b/test/tasks/Request4SuspendKtTest.kt @@ -3,29 +3,23 @@ package tasks import contributors.MockGithubService import contributors.expectedResults import contributors.testRequestData -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runBlockingTest import org.junit.Assert import org.junit.Test +@UseExperimental(ExperimentalCoroutinesApi::class) class Request4SuspendKtTest { @Test - fun testSuspend() = runBlocking { - val startTime = System.currentTimeMillis() + fun testSuspend() = runBlockingTest { + val startTime = currentTime val result = loadContributorsSuspend(MockGithubService, testRequestData) Assert.assertEquals("Wrong result for 'loadContributorsSuspend'", expectedResults.users, result) - val totalTime = System.currentTimeMillis() - startTime - /* - // TODO: uncomment this assertion + val totalTime = currentTime - startTime Assert.assertEquals( - "The calls run consequently, so the total virtual time should be 4000 ms: " + - "1000 for repos request plus (1000 + 1200 + 800) = 3000 for sequential contributors requests)", + "The calls run consequently," + + "so the total virtual time should be 4000 ms: ", expectedResults.timeFromStart, totalTime ) - */ - Assert.assertTrue( - "The calls run consequently, so the total time should be around 4000 ms: " + - "1000 for repos request plus (1000 + 1200 + 800) = 3000 for sequential contributors requests)", - totalTime in expectedResults.timeFromStart..(expectedResults.timeFromStart + 500) - ) } } \ No newline at end of file diff --git a/test/tasks/Request5ConcurrentKtTest.kt b/test/tasks/Request5ConcurrentKtTest.kt index 24c7e94..82d0846 100644 --- a/test/tasks/Request5ConcurrentKtTest.kt +++ b/test/tasks/Request5ConcurrentKtTest.kt @@ -3,29 +3,23 @@ package tasks import contributors.MockGithubService import contributors.expectedConcurrentResults import contributors.testRequestData -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runBlockingTest import org.junit.Assert import org.junit.Test +@UseExperimental(ExperimentalCoroutinesApi::class) class Request5ConcurrentKtTest { @Test - fun testConcurrent() = runBlocking { - val startTime = System.currentTimeMillis() + fun testConcurrent() = runBlockingTest { + val startTime = currentTime val result = loadContributorsConcurrent(MockGithubService, testRequestData) Assert.assertEquals("Wrong result for 'loadContributorsConcurrent'", expectedConcurrentResults.users, result) - val totalTime = System.currentTimeMillis() - startTime - /* - // TODO: uncomment this assertion + val totalTime = currentTime - 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 ) - */ - Assert.assertTrue( - "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)", - totalTime in expectedConcurrentResults.timeFromStart..(expectedConcurrentResults.timeFromStart + 500) - ) } } \ No newline at end of file diff --git a/test/tasks/Request6ProgressKtTest.kt b/test/tasks/Request6ProgressKtTest.kt index 4c9e441..a8da26d 100644 --- a/test/tasks/Request6ProgressKtTest.kt +++ b/test/tasks/Request6ProgressKtTest.kt @@ -3,24 +3,23 @@ package tasks import contributors.MockGithubService import contributors.progressResults import contributors.testRequestData -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runBlockingTest import org.junit.Assert import org.junit.Test +@UseExperimental(ExperimentalCoroutinesApi::class) class Request6ProgressKtTest { @Test - fun testProgress() = runBlocking { - val startTime = System.currentTimeMillis() + fun testProgress() = runBlockingTest { + val startTime = currentTime var index = 0 loadContributorsProgress(MockGithubService, testRequestData) { users, _ -> val expected = progressResults[index++] - val time = System.currentTimeMillis() - startTime - /* - // TODO: uncomment this assertion + val time = currentTime - startTime Assert.assertEquals("Expected intermediate result after virtual ${expected.timeFromStart} ms:", expected.timeFromStart, time) - */ Assert.assertEquals("Wrong intermediate result after $time:", expected.users, users) } } diff --git a/test/tasks/Request7ChannelsKtTest.kt b/test/tasks/Request7ChannelsKtTest.kt index d82d26a..628dc8e 100644 --- a/test/tasks/Request7ChannelsKtTest.kt +++ b/test/tasks/Request7ChannelsKtTest.kt @@ -3,24 +3,23 @@ package tasks import contributors.MockGithubService import contributors.concurrentProgressResults import contributors.testRequestData -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runBlockingTest import org.junit.Assert import org.junit.Test +@UseExperimental(ExperimentalCoroutinesApi::class) class Request7ChannelsKtTest { @Test - fun testChannels() = runBlocking { - val startTime = System.currentTimeMillis() + fun testChannels() = runBlockingTest { + val startTime = currentTime var index = 0 loadContributorsChannels(MockGithubService, testRequestData) { users, _ -> val expected = concurrentProgressResults[index++] - val time = System.currentTimeMillis() - startTime - /* - // TODO: uncomment this assertion + val time = currentTime - startTime Assert.assertEquals("Expected intermediate result after virtual ${expected.timeFromStart} ms:", - expected.timeFromStart, virtualTime) - */ + expected.timeFromStart, time) Assert.assertEquals("Wrong intermediate result after $time:", expected.users, users) } }