rabbah commented on a change in pull request #3211: implement 
ContainerFactory.cpuShare to fix #3110
URL: 
https://github.com/apache/incubator-openwhisk/pull/3211#discussion_r172494890
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerFactoryTests.scala
 ##########
 @@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk.core.containerpool.docker.test
+
+import common.StreamLogging
+import common.TimingHelpers
+import common.WskActorSystem
+import org.scalamock.scalatest.MockFactory
+import org.scalatest.BeforeAndAfterEach
+import org.scalatest.FlatSpec
+import org.scalatest.Matchers
+import scala.concurrent.Await
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import whisk.common.TransactionId
+import whisk.core.WhiskConfig
+import whisk.core.WhiskConfig._
+import whisk.core.containerpool.ContainerAddress
+import whisk.core.containerpool.ContainerArgsConfig
+import whisk.core.containerpool.ContainerId
+import whisk.core.containerpool.docker.DockerApiWithFileAccess
+import whisk.core.containerpool.docker.DockerContainerFactory
+import whisk.core.containerpool.docker.RuncApi
+import whisk.core.entity.InstanceId
+import whisk.core.entity.size._
+import whisk.core.entity.test.ExecHelpers
+class DockerContainerFactoryTests
+    extends FlatSpec
+    with Matchers
+    with MockFactory
+    with StreamLogging
+    with BeforeAndAfterEach
+    with WskActorSystem
+    with TimingHelpers
+    with ExecHelpers {
+
+  implicit val wskConfig = new WhiskConfig(Map(dockerImagePrefix -> null, 
dockerImageTag -> null))
+
+  behavior of "DockerContainerFactory"
+
+  it should "calculate cpu-share based on invoker config" in {
+
+    implicit val tid = TransactionId(0)
+    val dockerApiStub = mock[DockerApiWithFileAccess]
+    //setup run expectation
+    (dockerApiStub
+      .run(_: String, _: Seq[String])(_: TransactionId))
+      .expects(
+        "whisk/nodejs6action:latest",
+        Seq(
+          "--cpu-shares",
+          "32", //should be calculated as 1024/(numcore * sharefactor) via 
ContainerFactory.cpuShare
+          "--memory",
+          "10m",
+          "--memory-swap",
+          "10m",
+          "--network",
+          "net1",
+          "-e",
+          "__OW_API_HOST=://:",
+          "--dns",
+          "dns1",
+          "--dns",
+          "dns2",
+          "--name",
+          "testContainer",
+          "--env",
+          "e1",
+          "--env",
+          "e2"),
+        *)
+      .returning(Future.successful { ContainerId("fakecontainerid") })
+    //setup inspect expectation
+    (dockerApiStub
+      .inspectIPAddress(_: ContainerId, _: String)(_: TransactionId))
+      .expects(ContainerId("fakecontainerid"), "net1", *)
+      .returning(Future.successful { ContainerAddress("1.2.3.4", 1234) })
+    //setup rm expectation
+    (dockerApiStub
+      .rm(_: ContainerId)(_: TransactionId))
+      .expects(ContainerId("fakecontainerid"), *)
+      .returning(Future.successful(Unit))
 
 Review comment:
   hmm if the test is just to validate the cpu share, this seems like over 
engineering of the test (could you have tested just the config class itself in 
contrast for example?).
   
   i'm ok keeping the test as is but the test name/comment struck me relative 
to the actual code.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to