You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/07/10 02:34:31 UTC
[GitHub] dgrove-oss closed pull request #35: Update tests to pick up
upstream changes.
dgrove-oss closed pull request #35: Update tests to pick up upstream changes.
URL: https://github.com/apache/incubator-openwhisk-runtime-php/pull/35
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/.travis.yml b/.travis.yml
index 9e2ac3e..918d0cd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,7 +18,7 @@ before_install:
- "./tools/travis/setup.sh"
install: true
script:
- - "./tools/travis/build.sh && ./tools/travis/deploy.sh && ./tools/travis/test.sh"
+ - "./tools/travis/build.sh && ./tools/travis/test.sh"
deploy:
- provider: script
script: "./tools/travis/publish.sh openwhisk ${TRAVIS_TAG%@*} ${TRAVIS_TAG##*@}"
diff --git a/core/php7.1Action/CHANGELOG.md b/core/php7.1Action/CHANGELOG.md
index 57ff219..8ad347b 100644
--- a/core/php7.1Action/CHANGELOG.md
+++ b/core/php7.1Action/CHANGELOG.md
@@ -17,6 +17,10 @@
#
-->
+## 1.0.2
+Changes:
+ - Disallow re-initialization of function.
+
## 1.0.1
- Change: Update PHP to 7.1.18
diff --git a/core/php7.1Action/router.php b/core/php7.1Action/router.php
index 3c24ff3..76d8765 100644
--- a/core/php7.1Action/router.php
+++ b/core/php7.1Action/router.php
@@ -93,7 +93,9 @@ function init() : array
{
// check that we haven't already been initialised
if (file_exists(ACTION_CONFIG_FILE)) {
- throw new RuntimeException('Cannot initialize the action more than once.', 403);
+ writeTo("php://stdout", 'Error: Cannot initialize the action more than once.');
+ http_response_code(403);
+ return ['error' => 'Cannot initialize the action more than once.'];
}
// data is POSTed to us as a JSON string
@@ -106,7 +108,7 @@ function init() : array
$binary = $data['binary'] ?? false; // code is binary?
if (!$code) {
- throw new RuntimeException("No code to execute");
+ throw new RuntimeException("Missing main/no code to execute.");
}
if ($binary) {
diff --git a/core/php7.2Action/CHANGELOG.md b/core/php7.2Action/CHANGELOG.md
index 702b708..4e4c56e 100644
--- a/core/php7.2Action/CHANGELOG.md
+++ b/core/php7.2Action/CHANGELOG.md
@@ -17,6 +17,10 @@
#
-->
+## 1.0.1
+Changes:
+ - Disallow re-initialization of function.
+
## 1.0.0
Initial release
diff --git a/core/php7.2Action/router.php b/core/php7.2Action/router.php
index 890d55c..bbf50e1 100644
--- a/core/php7.2Action/router.php
+++ b/core/php7.2Action/router.php
@@ -124,7 +124,9 @@ function init() : array
{
// check that we haven't already been initialised
if (file_exists(ACTION_CONFIG_FILE)) {
- throw new RuntimeException('Cannot initialize the action more than once.', 403);
+ writeTo("php://stdout", 'Error: Cannot initialize the action more than once.');
+ http_response_code(403);
+ return ['error' => 'Cannot initialize the action more than once.'];
}
// data is POSTed to us as a JSON string
@@ -137,7 +139,7 @@ function init() : array
$binary = $data['binary'] ?? false; // code is binary?
if (!$code) {
- throw new RuntimeException("No code to execute");
+ throw new RuntimeException("Missing main/no code to execute.");
}
if ($binary) {
diff --git a/tests/.pydevproject b/tests/.pydevproject
deleted file mode 100644
index 40e9f40..0000000
--- a/tests/.pydevproject
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?eclipse-pydev version="1.0"?><pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
-</pydev_project>
diff --git a/tests/src/test/scala/runtime/actionContainers/Php71ActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/Php71ActionContainerTests.scala
index 03f42f3..44352d9 100644
--- a/tests/src/test/scala/runtime/actionContainers/Php71ActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/Php71ActionContainerTests.scala
@@ -24,4 +24,7 @@ import org.scalatest.junit.JUnitRunner
class Php71ActionContainerTests extends Php7ActionContainerTests {
override lazy val phpContainerImageName = "action-php-v7.1"
+
+ override val testLargeInput = TestConfig("", skipTest = true)
+
}
diff --git a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
index 000d0b0..430ea71 100644
--- a/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/Php7ActionContainerTests.scala
@@ -27,11 +27,10 @@ import spray.json._
@RunWith(classOf[JUnitRunner])
abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskActorSystem {
- // note: "out" will not be empty as the PHP web server outputs a message when
- // it starts up
+ // note: "out" will not be empty as the PHP web server outputs a message when it starts up
val enforceEmptyOutputStream = false
- lazy val phpContainerImageName = "action-php-v7.x"
+ lazy val phpContainerImageName: String = ???
override def withActionContainer(env: Map[String, String] = Map.empty)(code: ActionContainer => Unit) = {
withContainer(phpContainerImageName, env)(code)
@@ -41,30 +40,56 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
behavior of phpContainerImageName
- testEcho(Seq {
- (
- "PHP",
+ override val testNoSourceOrExec = TestConfig("")
+
+ override val testNotReturningJson = {
+ TestConfig(
+ """
+ |<?php
+ |function main(array $args) {
+ | return "not a json object";
+ |}
+ """.stripMargin,
+ enforceEmptyOutputStream = enforceEmptyOutputStream,
+ enforceEmptyErrorStream = false)
+ }
+
+ override val testInitCannotBeCalledMoreThanOnce = {
+ TestConfig(
"""
- |<?php
- |function main(array $args) : array {
- | echo 'hello stdout';
- | error_log('hello stderr');
- | return $args;
- |}
- """.stripMargin)
- })
-
- testNotReturningJson("""
|<?php
- |function main(array $args) {
- | return "not a json object";
+ |function main(array $args) : array {
+ | return $args;
|}
- """.stripMargin)
+ """.stripMargin,
+ enforceEmptyOutputStream = enforceEmptyOutputStream)
+ }
- testUnicode(Seq {
- (
- "PHP",
+ override val testEntryPointOtherThanMain = {
+ TestConfig(
"""
+ | <?php
+ | function niam(array $args) {
+ | return $args;
+ | }
+ """.stripMargin,
+ main = "niam",
+ enforceEmptyOutputStream = enforceEmptyOutputStream)
+ }
+
+ override val testEcho = {
+ TestConfig("""
+ |<?php
+ |function main(array $args) : array {
+ | echo 'hello stdout';
+ | error_log('hello stderr');
+ | return $args;
+ |}
+ """.stripMargin)
+ }
+
+ override val testUnicode = {
+ TestConfig("""
|<?php
|function main(array $args) : array {
| $str = $args['delimiter'] . " ☃ " . $args['delimiter'];
@@ -72,37 +97,37 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
| return ["winter" => $str];
|}
""".stripMargin.trim)
- })
+ }
- testEnv(
- Seq {
- (
- "PHP",
- """
- |<?php
- |function main(array $args) : array {
- | return [
- | "env" => $_ENV,
- | "api_host" => $_ENV['__OW_API_HOST'],
- | "api_key" => $_ENV['__OW_API_KEY'],
- | "namespace" => $_ENV['__OW_NAMESPACE'],
- | "action_name" => $_ENV['__OW_ACTION_NAME'],
- | "activation_id" => $_ENV['__OW_ACTIVATION_ID'],
- | "deadline" => $_ENV['__OW_DEADLINE'],
- | ];
- |}
- """.stripMargin.trim)
- },
- enforceEmptyOutputStream)
-
- testInitCannotBeCalledMoreThanOnce("""
- |<?php
- |function main(array $args) : array {
- | echo 'hello stdout';
- | error_log('hello stderr');
- | return $args;
- |}
- """.stripMargin)
+ override val testEnv = {
+ TestConfig(
+ """
+ |<?php
+ |function main(array $args) : array {
+ | return [
+ | "env" => $_ENV,
+ | "api_host" => $_ENV['__OW_API_HOST'],
+ | "api_key" => $_ENV['__OW_API_KEY'],
+ | "namespace" => $_ENV['__OW_NAMESPACE'],
+ | "action_name" => $_ENV['__OW_ACTION_NAME'],
+ | "activation_id" => $_ENV['__OW_ACTIVATION_ID'],
+ | "deadline" => $_ENV['__OW_DEADLINE'],
+ | ];
+ |}
+ """.stripMargin.trim,
+ enforceEmptyOutputStream = enforceEmptyOutputStream)
+ }
+
+ override val testLargeInput = {
+ TestConfig("""
+ |<?php
+ |function main(array $args) : array {
+ | echo 'hello stdout';
+ | error_log('hello stderr');
+ | return $args;
+ |}
+ """.stripMargin)
+ }
it should "fail to initialize with bad code" in {
val (out, err) = withPhp7Container { c =>
@@ -127,19 +152,6 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
})
}
- it should "fail to initialize with no code" in {
- val (out, err) = withPhp7Container { c =>
- val code = ""
-
- val (initCode, error) = c.init(initPayload(code))
-
- initCode should not be (200)
- error shouldBe a[Some[_]]
- error.get shouldBe a[JsObject]
- error.get.fields("error").toString should include("No code to execute")
- }
- }
-
it should "return some error on action error" in {
val (out, err) = withPhp7Container { c =>
val code = """
@@ -467,21 +479,6 @@ abstract class Php7ActionContainerTests extends BasicActionRunnerTests with WskA
})
}
- it should "support actions using non-default entry point" in {
- val (out, err) = withPhp7Container { c =>
- val code = """
- | <?php
- | function niam(array $args) {
- | return [result => "it works"];
- | }
- """.stripMargin
-
- c.init(initPayload(code, main = "niam"))._1 should be(200)
- val (runCode, runRes) = c.run(runPayload(JsObject()))
- runRes.get.fields.get("result") shouldBe Some(JsString("it works"))
- }
- }
-
it should "support zipped actions using non-default entry point" in {
val srcs = Seq(Seq("index.php") -> """
| <?php
diff --git a/tools/travis/build.sh b/tools/travis/build.sh
index 40d6d7a..e3aa931 100755
--- a/tools/travis/build.sh
+++ b/tools/travis/build.sh
@@ -27,25 +27,17 @@ UTILDIR="$ROOTDIR/../incubator-openwhisk-utilities"
export OPENWHISK_HOME=$WHISKDIR
-IMAGE_PREFIX="testing"
-
# run scancode using the ASF Release configuration
cd $UTILDIR
scancode/scanCode.py --config scancode/ASF-Release.cfg $ROOTDIR
-# Build OpenWhisk
+# Build OpenWhisk deps before we run tests
cd $WHISKDIR
-
-#pull down images
-docker pull openwhisk/controller
-docker tag openwhisk/controller ${IMAGE_PREFIX}/controller
-docker pull openwhisk/invoker
-docker tag openwhisk/invoker ${IMAGE_PREFIX}/invoker
-docker pull openwhisk/nodejs6action
-docker tag openwhisk/nodejs6action ${IMAGE_PREFIX}/nodejs6action
-
TERM=dumb ./gradlew install
+# Mock file (works around bug upstream)
+echo "openwhisk.home=$WHISKDIR" > whisk.properties
+echo "vcap.services.file=" >> whisk.properties
# Build runtime
cd $ROOTDIR
-TERM=dumb ./gradlew distDocker -PdockerImagePrefix=${IMAGE_PREFIX}
+TERM=dumb ./gradlew distDocker
diff --git a/tools/travis/deploy.sh b/tools/travis/deploy.sh
deleted file mode 100755
index 58b0988..0000000
--- a/tools/travis/deploy.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-set -ex
-
-# Build script for Travis-CI.
-
-SCRIPTDIR=$(cd $(dirname "$0") && pwd)
-ROOTDIR="$SCRIPTDIR/../.."
-WHISKDIR="$ROOTDIR/../openwhisk"
-
-export OPENWHISK_HOME=$WHISKDIR
-
-IMAGE_PREFIX="testing"
-
-# Deploy OpenWhisk
-cd $WHISKDIR/ansible
-ANSIBLE_CMD="ansible-playbook -i ${ROOTDIR}/ansible/environments/local -e docker_image_prefix=${IMAGE_PREFIX}"
-$ANSIBLE_CMD setup.yml
-$ANSIBLE_CMD prereq.yml
-$ANSIBLE_CMD couchdb.yml
-$ANSIBLE_CMD initdb.yml
-$ANSIBLE_CMD wipe.yml
-$ANSIBLE_CMD openwhisk.yml -e cli_installation_mode=remote
-
-docker images
-docker ps
-
-cat $WHISKDIR/whisk.properties
-curl -s -k https://172.17.0.1 | jq .
-curl -s -k https://172.17.0.1/api/v1 | jq .
-
-#Deployment
-WHISK_APIHOST="172.17.0.1"
-WHISK_AUTH=`cat ${WHISKDIR}/ansible/files/auth.guest`
-WHISK_CLI="${WHISKDIR}/bin/wsk -i"
-
-${WHISK_CLI} property set --apihost ${WHISK_APIHOST} --auth ${WHISK_AUTH}
-${WHISK_CLI} property get
diff --git a/tools/travis/test.sh b/tools/travis/test.sh
index 05d080e..a5b249d 100755
--- a/tools/travis/test.sh
+++ b/tools/travis/test.sh
@@ -25,10 +25,6 @@ ROOTDIR="$SCRIPTDIR/../.."
WHISKDIR="$ROOTDIR/../openwhisk"
export OPENWHISK_HOME=$WHISKDIR
-
cd ${ROOTDIR}
TERM=dumb ./gradlew :tests:checkScalafmtAll
TERM=dumb ./gradlew :tests:test
-
-
-
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services