Skip to content

Commit

Permalink
Add test for multiple throttles
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Nov 22, 2023
1 parent 9b5d9bd commit 439df31
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions modules/tests/shared/src/test/scala/crystal/DeglitcherSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class DeglitcherSuite extends CatsEffectSuite {
TestControl
.executeEmbed {
Deglitcher[IO](100.millis).flatMap { deglitcher =>
server(() -> 1.millis, () -> 1.millis, () -> 1.millis)
server(0 -> 1.millis, 1 -> 1.millis, 2 -> 1.millis)
.through(deglitcher.debounce)
.evalMap(_ => IO.realTime)
.evalMap(IO.realTime.tupleLeft(_))
.compile
.toList
}
}
.assertEquals(List(1.millis, 2.millis, 3.millis))
.assertEquals(List(0 -> 1.millis, 1 -> 2.millis, 2 -> 3.millis))
}

test("respects throttling") {
Expand All @@ -53,4 +53,26 @@ class DeglitcherSuite extends CatsEffectSuite {
.assertEquals(List(0 -> 0.millis, 2 -> 101.millis, 3 -> 230.millis))
}

test("respects multiple throttles") {
TestControl
.executeEmbed {
Deglitcher[IO](100.millis).flatMap { deglitcher =>
server(0 -> 20.millis)
.through(deglitcher.debounce)
.evalMap(IO.realTime.tupleLeft(_))
.compile
.toList
.background
.use { result =>
IO.sleep(10.millis) *>
deglitcher.throttle *>
IO.sleep(40.millis) *>
deglitcher.throttle *>
result.flatMap(_.embedError)
}
}
}
.assertEquals(List(0 -> 150.millis))
}

}

0 comments on commit 439df31

Please sign in to comment.