Skip to content

Commit

Permalink
Remove flaky test - which wasn't testing the property it described. C…
Browse files Browse the repository at this point in the history
…loses #59
  • Loading branch information
adamw committed Feb 21, 2024
1 parent 63b616b commit b4a1ea1
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions examples/src/test/scala/ox/ratelimiter/test/RateLimiterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,3 @@ class RateLimiterTest extends AnyFlatSpec with Matchers with Eventually with Int
}
}
}

it should "maintain the rate limit in all time windows" in {
RateLimiter.withRateLimiter(10, 1.second) { rateLimiter =>
val complete = new AtomicReference(Vector.empty[Long])
for (i <- 1 to 20) {
rateLimiter.runLimited {
println(s"${LocalTime.now()} Running $i")
complete.updateAndGet(_ :+ System.currentTimeMillis())
}
Thread.sleep(100)
}

eventually {
complete.get() should have size (20)

// the spacing should be preserved. In a token bucket algorithm, at some point the bucket would refill and
// all pending futures would be run. In a windowed algorithm, the spacings are preserved.
val secondHalf = complete.get().slice(10, 20)
secondHalf.zip(secondHalf.tail).map { case (p, n) => n - p }.foreach { d =>
d should be <= (150L)
d should be >= (50L)
}
}
}
}

0 comments on commit b4a1ea1

Please sign in to comment.