markusthoemmes commented on a change in pull request #4496: Simplify throttle
code for API GW Tests
URL:
https://github.com/apache/incubator-openwhisk/pull/4496#discussion_r288534176
##########
File path:
tests/src/test/scala/org/apache/openwhisk/core/cli/test/BaseApiGwTests.scala
##########
@@ -56,29 +55,10 @@ abstract class BaseApiGwTests extends TestHelpers with
WskTestHelpers with Befor
// Custom CLI properties file
val cliWskPropsFile = File.createTempFile("wskprops", ".tmp")
- /**
- * Expected to be called before each action invocation to
- * settle the throttle when there isn't enough capacity to handle the test.
- */
- def checkThrottle(maxInvocationsBeforeThrottle: Int = maxActionsPerMin,
throttlePercent: Int = 50) = {
- val t = Instant.now
- val tminus60 = t.minusSeconds(60)
- val invocationsLast60Seconds =
invocationTimes.filter(_.isAfter(tminus60)).sorted
- val invocationCount = invocationsLast60Seconds.length
- println(s"Action invokes within last minute: ${invocationCount}")
-
- if (invocationCount >= maxInvocationsBeforeThrottle && throttlePercent >=
1) {
- val numInvocationsToClear = max(invocationCount / (100 /
throttlePercent), 1)
- val invocationToClear = invocationsLast60Seconds(numInvocationsToClear -
1)
- println(
- s"throttling ${throttlePercent}% of action invocations within last
minute = ($numInvocationsToClear) invocations")
- val throttleTime = 60.seconds.toMillis - (t.toEpochMilli -
invocationToClear.toEpochMilli)
-
- println(s"Waiting ${throttleTime} milliseconds to settle the throttle")
- Thread.sleep(throttleTime)
- }
-
- invocationTimes += Instant.now
+ def throttle(maxInvocationsBeforeThrottle: Int = maxActionsPerMin) = {
+ val throttleTime = (60.seconds.toMillis / maxInvocationsBeforeThrottle *
1.1).toInt
Review comment:
One of the main things I see us losing is time. I agree that
functionality-wise this is fine and maybe even better. However, you lose the
ability to use all the elapsed time between tests or when not firing any
actions (for example when creating them) which the old code took into account.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services