1 /* 2 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.test 6 7 import kotlinx.coroutines.* 8 import org.junit.* 9 import java.time.* 10 11 const val SLOW = 10_000L 12 13 /** 14 * Assert a block completes within a second or fail the suite 15 */ assertRunsFastnull16suspend fun CoroutineScope.assertRunsFast(block: suspend CoroutineScope.() -> Unit) { 17 val start = Instant.now().toEpochMilli() 18 // don't need to be fancy with timeouts here since anything longer than a few ms is an error 19 block() 20 val duration = Instant.now().minusMillis(start).toEpochMilli() 21 Assert.assertTrue("All tests must complete within 2000ms (use longer timeouts to cause failure)", duration < 2_000) 22 } 23