Skip to content

Commit

Permalink
test: add showcases of timeout control and delay execution
Browse files Browse the repository at this point in the history
  • Loading branch information
oldratlee committed Feb 23, 2023
1 parent 88cb4f9 commit 6386d9b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.foldright.testutils.*
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.longs.shouldBeGreaterThanOrEqual
import io.kotest.matchers.longs.shouldBeBetween
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
Expand Down Expand Up @@ -322,15 +322,16 @@ class CompletableFutureUsageShowcaseTest : FunSpec({

test("delay execution") {
val tick = currentTimeMillis()
val delay = 3L
val delay = 5L

val delayer = CompletableFuture.delayedExecutor(delay, TimeUnit.MILLISECONDS)

@Suppress("BlockingMethodInNonBlockingContext")
val duration = CompletableFuture.supplyAsync({
currentTimeMillis() - tick
}, delayer).get()
duration shouldBeGreaterThanOrEqual 10

duration.shouldBeBetween(delay, delay + 2)
}

xtest("performance CF then*").config(invocations = 10) {
Expand Down

0 comments on commit 6386d9b

Please sign in to comment.