mhenke1 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_r289934644
 
 

 ##########
 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:
   @markusthoemmes Sorry for answering late. With the latest commit I reverted 
back to the original throttling code. I just left the additional pause to calm 
down the throttle before running the tests.

----------------------------------------------------------------
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

Reply via email to