Skip to content

Commit 9e0f226

Browse files
committed
Add simple test on interval changing
1 parent 323e6b6 commit 9e0f226

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

modules/core/src/test/scala/LimiterSuite.scala

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class LimiterSuite extends BaseSuite {
3535
productionInterval: FiniteDuration,
3636
producers: Int,
3737
jobsPerProducer: Int,
38-
jobCompletion: FiniteDuration
38+
jobCompletion: FiniteDuration,
39+
control: Limiter[IO] => IO[Unit] = _ => IO.unit
3940
): IO[Vector[FiniteDuration]] =
4041
Limiter.start[IO](desiredInterval, maxConcurrent).use { limiter =>
4142
def job = IO.monotonic <* IO.sleep(jobCompletion)
@@ -59,7 +60,7 @@ class LimiterSuite extends BaseSuite {
5960
.compile
6061
.toVector
6162

62-
results
63+
control(limiter).background.surround(results)
6364
}
6465

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

129130
val expected = Vector(
130-
50L, 50, 200, 50, 50, 200, 50, 50, 200
131+
50, 50, 200, 50, 50, 200, 50, 50, 200
132+
).map(_.millis)
133+
134+
TestControl.executeEmbed(prog).assertEquals(expected)
135+
}
136+
137+
test("interval change") {
138+
val prog = simulation(
139+
desiredInterval = 200.millis,
140+
maxConcurrent = Int.MaxValue,
141+
productionInterval = 1.millis,
142+
producers = 1,
143+
jobsPerProducer = 10,
144+
jobCompletion = 0.seconds,
145+
control =
146+
limiter => IO.sleep(1.seconds) >> limiter.setMinInterval(300.millis)
147+
)
148+
149+
val expected = Vector(
150+
200, 200, 200, 200, 200, 300, 300, 300, 300
131151
).map(_.millis)
132152

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

0 commit comments

Comments
 (0)