Browse Source

MINOR: fix flaky ConsumerBounceTest.testClose

Fixes `java.util.concurrent.ExecutionException: java.lang.AssertionError: Close finished too quickly 5999`.

The close test sets a close duration in milliseconds, but measures the time taken in nanoseconds. This leads to small error due to the resolution in each, where the close is deemed to have taken too little time.

When I measured the start and end with nanoTime, I found the time taken to close was `5999641566 ns (5999.6ms)` which seems close enough to be a resolution error. I've run the test 50 times and have not hit the "Close finished too quickly" issue again, whereas previously I hit a failure pretty quickly.

Author: Lucas Bradstreet <lucas@confluent.io>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes #7683 from lbradstreet/flaky-consumer-bounce-test
pull/7692/head
Lucas Bradstreet 5 years ago committed by Manikumar Reddy
parent
commit
2bd6b6ff0f
  1. 4
      core/src/test/scala/integration/kafka/api/ConsumerBounceTest.scala

4
core/src/test/scala/integration/kafka/api/ConsumerBounceTest.scala

@ -457,10 +457,10 @@ class ConsumerBounceTest extends AbstractConsumerTest with Logging { @@ -457,10 +457,10 @@ class ConsumerBounceTest extends AbstractConsumerTest with Logging {
closeTimeoutMs: Long, minCloseTimeMs: Option[Long], maxCloseTimeMs: Option[Long]): Future[Any] = {
executor.submit(CoreUtils.runnable {
val closeGraceTimeMs = 2000
val startNanos = System.nanoTime
val startMs = System.currentTimeMillis()
info("Closing consumer with timeout " + closeTimeoutMs + " ms.")
consumer.close(time.Duration.ofMillis(closeTimeoutMs))
val timeTakenMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime - startNanos)
val timeTakenMs = System.currentTimeMillis() - startMs
maxCloseTimeMs.foreach { ms =>
assertTrue("Close took too long " + timeTakenMs, timeTakenMs < ms + closeGraceTimeMs)
}

Loading…
Cancel
Save