You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2018/02/27 21:11:51 UTC

[incubator-openwhisk] branch master updated: Allow container tests to run without a proxy. (#3335)

This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 7218a48  Allow container tests to run without a proxy. (#3335)
7218a48 is described below

commit 7218a48d94846c23a853ece185b845bb59d4a628
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Tue Feb 27 16:11:49 2018 -0500

    Allow container tests to run without a proxy. (#3335)
---
 ansible/README.md                                  | 17 -------------
 .../scala/actionContainers/ActionContainer.scala   | 28 +++++++++++++++-------
 .../DockerExampleContainerTests.scala              |  2 +-
 3 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/ansible/README.md b/ansible/README.md
index 7651e63..b4accdd 100644
--- a/ansible/README.md
+++ b/ansible/README.md
@@ -42,23 +42,6 @@ An expedient workaround is to add alias for `docker0` network to loopback interf
 sudo ifconfig lo0 alias 172.17.0.1/24
 ```
 
-##### Setup proxy container to run unit tests (optional)
-
-This step is only required to run tests with Docker for Mac.
-If you do not run tests locally, you can just skip this step.
-
-```
-docker run -d -p 3128:3128 style95/squid:3.5.26-p1
-```
-
-You need to configure gradle proxy settings.
-
-**~/.gradle/gradle.properties**
-```
-systemProp.http.proxyHost=localhost
-systemProp.http.proxyPort=3128
-```
-
 ### Using Ansible
 **Caveat:** All Ansible commands are meant to be executed from the `ansible` directory.
 This is important because that's where `ansible.cfg` is located which contains generic settings that are needed for the remaining steps.
diff --git a/tests/src/test/scala/actionContainers/ActionContainer.scala b/tests/src/test/scala/actionContainers/ActionContainer.scala
index 94f6763..4f6ef24 100644
--- a/tests/src/test/scala/actionContainers/ActionContainer.scala
+++ b/tests/src/test/scala/actionContainers/ActionContainer.scala
@@ -135,19 +135,31 @@ object ActionContainer {
       case (k, v) => s"-e ${k}=${v}"
     } mkString (" ")
 
-    // We create the container...
-    val runOut = awaitDocker(s"run --name $name $envArgs -d $imageName", 10 seconds)
-    assert(runOut._1 == 0, "'docker run' did not exit with 0: " + runOut)
+    // We create the container... and find out its IP address...
+    def createContainer(portFwd: Option[Int] = None): Unit = {
+      val runOut = awaitDocker(
+        s"run ${portFwd.map(p => s"-p $p:8080").getOrElse("")} --name $name $envArgs -d $imageName",
+        10 seconds)
+      assert(runOut._1 == 0, "'docker run' did not exit with 0: " + runOut)
+    }
 
     // ...find out its IP address...
-    val ipOut = awaitDocker(s"""inspect --format '{{.NetworkSettings.IPAddress}}' $name""", 10 seconds)
-    assert(ipOut._1 == 0, "'docker inspect did not exit with 0")
-    val ip = ipOut._2.replaceAll("""[^0-9.]""", "")
+    val (ip, port) = if (WhiskProperties.getProperty("whisk.version.name") == "local") {
+      val p = 8988 // port must be available or docker run will fail
+      createContainer(Some(p))
+      Thread.sleep(1500) // let container/server come up cleanly
+      ("localhost", p)
+    } else { // "mac"
+      createContainer()
+      val ipOut = awaitDocker(s"""inspect --format '{{.NetworkSettings.IPAddress}}' $name""", 10 seconds)
+      assert(ipOut._1 == 0, "'docker inspect did not exit with 0")
+      (ipOut._2.replaceAll("""[^0-9.]""", ""), 8080)
+    }
 
     // ...we create an instance of the mock container interface...
     val mock = new ActionContainer {
-      def init(value: JsValue) = syncPost(ip, 8080, "/init", value)
-      def run(value: JsValue) = syncPost(ip, 8080, "/run", value)
+      def init(value: JsValue) = syncPost(ip, port, "/init", value)
+      def run(value: JsValue) = syncPost(ip, port, "/run", value)
     }
 
     try {
diff --git a/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala b/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala
index 5fd85d3..c5bfdba 100644
--- a/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/DockerExampleContainerTests.scala
@@ -137,7 +137,7 @@ class DockerExampleContainerTests extends ActionProxyContainerTestUtils with Wsk
 
   it should "timeout bad proxy with exception" in {
     val (out, err) = withContainer("badproxy") { c =>
-      a[TimeoutException] should be thrownBy {
+      an[IllegalStateException] should be thrownBy {
         val (code, out) = c.init(JsObject())
         println(code, out)
       }

-- 
To stop receiving notification emails like this one, please contact
csantanapr@apache.org.