apovzner commented on a change in pull request #8768: URL: https://github.com/apache/kafka/pull/8768#discussion_r453130277
########## File path: core/src/test/scala/unit/kafka/network/ConnectionQuotasTest.scala ########## @@ -329,15 +613,46 @@ class ConnectionQuotasTest { } // this method must be called on a separate thread, because connectionQuotas.inc() may block + private def acceptConnectionsAndVerifyRate(connectionQuotas: ConnectionQuotas, + listenerDesc: ListenerDesc, + numConnections: Long, + timeIntervalMs: Long, + expectedRate: Int, + epsilon: Int) : Unit = { + val startTimeMs = System.currentTimeMillis + acceptConnections(connectionQuotas, listenerDesc.listenerName, listenerDesc.defaultIp, numConnections, timeIntervalMs) + val elapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis - startTimeMs) + val actualRate = (numConnections.toDouble / elapsedSeconds).toInt + if (actualRate - epsilon > expectedRate || actualRate + epsilon < expectedRate) + throw new TestFailedException( + (e: StackDepthException) => + Some(s"Expected rate $expectedRate, but got $actualRate ($numConnections connections / $elapsedSeconds sec)"), + None, + Position.here) Review comment: Yes, I had a memory that asserting from another thread would not do the right thing, but I think that was a very old memory. Checked and it works well. Replaced with `assertTrue`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org