diff --git a/test/tasks/Request4SuspendKtTest.kt b/test/tasks/Request4SuspendKtTest.kt index af92edb..47515ad 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 +@OptIn(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..6f1933b 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 +@OptIn(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..4d9f446 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 +@OptIn(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 f377e85..d054f7f 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 +@OptIn(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, time) - */ Assert.assertEquals("Wrong intermediate result after $time:", expected.users, users) } }