Skip to content

Commit

Permalink
Add simple test on interval changing
Browse files Browse the repository at this point in the history
  • Loading branch information
SystemFw committed Apr 20, 2022
1 parent 323e6b6 commit 9e0f226
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions modules/core/src/test/scala/LimiterSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class LimiterSuite extends BaseSuite {
productionInterval: FiniteDuration,
producers: Int,
jobsPerProducer: Int,
jobCompletion: FiniteDuration
jobCompletion: FiniteDuration,
control: Limiter[IO] => IO[Unit] = _ => IO.unit
): IO[Vector[FiniteDuration]] =
Limiter.start[IO](desiredInterval, maxConcurrent).use { limiter =>
def job = IO.monotonic <* IO.sleep(jobCompletion)
Expand All @@ -59,7 +60,7 @@ class LimiterSuite extends BaseSuite {
.compile
.toVector

results
control(limiter).background.surround(results)
}

test("submit semantics should return the result of the submitted job") {
Expand Down Expand Up @@ -127,7 +128,26 @@ class LimiterSuite extends BaseSuite {
)

val expected = Vector(
50L, 50, 200, 50, 50, 200, 50, 50, 200
50, 50, 200, 50, 50, 200, 50, 50, 200
).map(_.millis)

TestControl.executeEmbed(prog).assertEquals(expected)
}

test("interval change") {
val prog = simulation(
desiredInterval = 200.millis,
maxConcurrent = Int.MaxValue,
productionInterval = 1.millis,
producers = 1,
jobsPerProducer = 10,
jobCompletion = 0.seconds,
control =
limiter => IO.sleep(1.seconds) >> limiter.setMinInterval(300.millis)
)

val expected = Vector(
200, 200, 200, 200, 200, 300, 300, 300, 300
).map(_.millis)

TestControl.executeEmbed(prog).assertEquals(expected)
Expand Down

0 comments on commit 9e0f226

Please sign in to comment.