markusthoemmes commented on a change in pull request #2995: At most 10 `docker 
run` commands are allowed in parallel
URL: 
https://github.com/apache/incubator-openwhisk/pull/2995#discussion_r152567845
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/containerpool/docker/test/DockerClientTests.scala
 ##########
 @@ -169,6 +175,101 @@ class DockerClientTests extends FlatSpec with Matchers 
with StreamLogging with B
     }
   }
 
+  it should "limit the number of concurrent docker run invocations" in {
+    // Delay execution of Docker run command
+    val firstRunPromise = Promise[String]()
+
+    val firstContainerId = ContainerId("1" * 64)
+    val secondContainerId = ContainerId("2" * 64)
+
+    var runCmdCount = 0
+    val dc = new DockerClient()(global) {
+      override val dockerCmd = Seq(dockerCommand)
+      override def executeProcess(args: String*)(implicit ec: 
ExecutionContext) = {
+        runCmdCount += 1
+        runCmdCount match {
+          case 1 => firstRunPromise.future
+          case 2 => Future.successful(secondContainerId.asString)
+          case _ => Future.failed(new Throwable())
+        }
+      }
+      // Need to override the semaphore, otherwise the tested code will still
+      // create the semaphore with the original value of maxParallelRuns.
+      override val maxParallelRuns = 1
+      override val runSemaphore = new Semaphore( /* permits= */ 
maxParallelRuns, /* fair= */ true)
+    }
+
+    val image = "image"
+    val args = Seq("args")
+
+    val firstRunResult = dc.run(image, args)
+    val secondRunResult = dc.run(image, args)
+
+    // The tested code won't reach the mocked executeProcess() and thus, 
increase runCmdCount,
+    // until at least one Future is successfully completed. For this reason, 
it takes
+    // some time until the following matcher is successful.
+    eventually(timeout(scaled(Span(5, Seconds)))) { runCmdCount shouldBe 1 }
 
 Review comment:
   Can this globally be solved by using a `PatienceConfig`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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