Permalink
Browse files

support for dockerized tests, and parallelized tests

  • Loading branch information...
starpit committed Nov 4, 2017
1 parent 70e65ab commit a3857fb4728a8a3e8678aa495e53648274609df1
View
@@ -0,0 +1 @@
**/node_modules
View
@@ -44,5 +44,5 @@ install:
- cat ~/.wskprops
- Xvfb :99 -screen 0 1400x1050x24 > /dev/null 2>&1 &
script: (cd tests && ./bin/runLocal.sh)
script: (cd tests && npm run test)
View
@@ -0,0 +1,25 @@
FROM starpit/ibm-functions-shell-base
WORKDIR /tests
# auth keys
ADD .openwhisk-shell /.openwhisk-shell
ADD dist /dist
RUN cd /dist && npm install
# some fake bits needed by compile.js
RUN echo "API_HOST=foo" > ~/.wskprops
RUN echo "AUTH=bar" >> ~/.wskprops
RUN echo "foof" > /tmp/foo
ADD app /app
RUN cd /app && npm install --unsafe-perm
# remove the fake bits
RUN rm ~/.wskprops
ADD tests /tests
RUN cd /tests && npm install
CMD ./bin/runWithXvfb.sh
View
@@ -0,0 +1,47 @@
#
# Copyright 2017 IBM Corporation
#
# Licensed 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.
#
#!/usr/bin/env bash
#
# This script tries to orchestrate the parallel execution of the test
# layers in such a way as to minimize too much concurrent load on a
# poor little travis instance, and also load balance the runs to
# maximize parallel efficiency.
#
# Optionally, you can pass in a list of the layers you'd like to run.
# NOTE: If you go this route, do not repeat a layer, e.g. attempt
# to run layer 08 twice in parallel. This is not (yet) supported.
#
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
cd "$SCRIPTDIR"
START_TIME=$SECONDS # remember when we started, so that we can report elapsed time
if [ "$#" -ne 0 ]; then
./runDocker.sh $@
else
./runDocker.sh 01 02 08 05 06 # these layers are shorter
if [ $? != 0 ]; then exit 1; fi # oops?
./runDocker.sh 03 04 07 # these layers are longer
if [ $? != 0 ]; then exit 1; fi # oops?
fi
# finally, report elapsed time
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Tests completed successfully in $(($ELAPSED_TIME/60)):$(($ELAPSED_TIME%60))"
View
@@ -0,0 +1,90 @@
#
# Copyright 2017 IBM Corporation
#
# Licensed 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.
#
#!/usr/bin/env bash
#
# This script runs a give layer, or list of layers, and runs them in
# parallel, isolated within docker containers. You will see the mocha
# output of how the tests proceed, but you will not be able to see the
# tests run visually. If this is what you need, then use `runLocal.sh`
# directly.
#
if [ -z "$API_HOST" ]; then
. ~/.wskprops
export API_HOST=$APIHOST
fi
if [ -z "$REDIS_URL" ]; then
REDIS_IP='192.168.33.13'
#redis-cli -h ${REDIS_IP} ping
export REDIS_URL="redis://${REDIS_IP}:6379"
fi
if [ -z "$REDIS_URL" ]; then
echo "Could not find redis"
exit 1
else
echo "Using this redis: ${REDIS_URL}"
fi
WHICH=${@-tests/passes/*}
idx=0
for i in $WHICH; do
LAYER=`basename $i`
NAME="shell-test-${LAYER}"
# make sure each layer has its own DISPLAY
idx=$((idx + 1))
DISPLAY=$(( 90 + $idx ))
PORT=$((9515 + $idx ))
docker rm "${NAME}" 2> /dev/null
echo -n "Starting layer=${LAYER} name=${NAME} DISPLAY=$DISPLAY containerId="
docker run \
--name "${NAME}" \
-d \
--net=host \
-e CHROMEDRIVER_PORT=$PORT \
-e KEY_FROM_LAYER=true \
-e DISPLAY=":$DISPLAY" \
-e LAYER=$LAYER \
-e REDIS_URL=$REDIS_URL \
-e API_HOST=$API_HOST \
shell-test
done
# wait for them to complete
for i in $WHICH; do
LAYER=`basename $i`
NAME="shell-test-${LAYER}"
docker logs -f "${NAME}" 2> /dev/null &
TAIL=$!
EXITCODE=`docker wait "${NAME}"`
kill $TAIL 2> /dev/null
if [ $EXITCODE != 0 ]; then
exit 1
fi
# optionally remove the docker container when the test is done
# docker rm "${NAME}"
done
View
@@ -16,12 +16,29 @@
#!/usr/bin/env bash
. ~/.wskprops
# the | tee should fail if runTest fails
set -o pipefail
if [ -z "$API_HOST" ]; then
. ~/.wskprops
export API_HOST=$APIHOST
fi
if [ ! -f ~/.wskprops ]; then
echo "APIHOST=$API_HOST" > ~/.wskprops
echo "INSECURE_SSL=true" >> ~/.wskprops
fi
export API_HOST=$APIHOST
export KEY_FROM_LAYER=true
export PATH=./node_modules/.bin:$PATH
if [ -z "$REDIS_URL" ]; then
REDIS_IP=`netstat -rn | awk '$NF=="lo0" && $3=="UGSc" { print substr($1, 1, index($1, "/") - 1)}'`
if [ $? == 0 ]; then
export REDIS_URL="redis://${REDIS_IP}:6379"
fi
fi
if [ -z "$REDIS_URL" ]; then
# do we need to start redis ourselves?
redis-server > /dev/null &
@@ -33,29 +50,24 @@ trap finished INT
function finished {
if [ -n "$REDIS_PID" ]; then
kill ${REDIS_PID}
kill ${REDIS_PID} 2> /dev/null
fi
}
if [ -z "$REDIS_URL" ]; then
REDIS_IP=`netstat -rn | awk '$NF=="lo0" && $3=="UGSc" { print substr($1, 1, index($1, "/") - 1)}'`
export REDIS_URL="redis://${REDIS_IP}:6379"
fi
if [ ! -d logs ]; then
mkdir logs
fi
rm logs/* 2> /dev/null
LAYER=${1-"*"}
# the | tee should fail if runTest fails
set -o pipefail
if [ -z "${LAYER}" ]; then
LAYER=${1-"*"}
fi
idx=1
for i in tests/passes/$LAYER; do
LAYER=`basename $i`
echo $LAYER
# echo $LAYER
LAYER=$LAYER ./bin/runTest.sh 2>&1 | tee logs/$LAYER.out
if [ $? != 0 ]; then
View
@@ -16,18 +16,23 @@
#!/usr/bin/env bash
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
ROOTDIR="$SCRIPTDIR/../.."
if [ -n "$LAYER" ]; then
# user asked to run tests in just one specified layer, e.g. "07"
if [ -n "KEY_FROM_LAYER" ]; then
if [ -n "$KEY_FROM_LAYER" ]; then
# user asked to pick up a previously configured auth key
DIR=$HOME/.openwhisk-shell/keys
DIR=$ROOTDIR/.openwhisk-shell/keys
export __OW_API_KEY=`cat $DIR/${LAYER}`
export AUTH=`cat $DIR/${LAYER}`
export __OW_API_KEY="$AUTH"
export TEST_ORG=""
export TEST_SPACE="ns${LAYER}"
echo "Key from layer $TEST_SPACE"
if [ -f "$DIR/${LAYER}b" ]; then
# some layers need a second auth and namespace
export AUTH2=`cat $DIR/${LAYER}b`
View
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
Xvfb ${DISPLAY-99} -ac &
sleep 5
$SCRIPTDIR/runLocal.sh $@
View
@@ -0,0 +1,9 @@
FROM node:8.9-slim
# install debian packages
# note: git is needed by npm install in tests
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y \
git xvfb dbus dbus-x11 google-chrome-stable libnotify-cil-dev make g++
View
@@ -0,0 +1 @@
Base docker image for tests
View
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
docker build -t starpit/ibm-functions-shell-base .
View
@@ -44,6 +44,9 @@ exports.before = (ctx, {fuzz}={}) => function() {
waitTimeout: process.env.TIMEOUT || 60000,
args: [ appMain ]
}
if (process.env.CHROMEDRIVER_PORT) {
opts.port = process.env.CHROMEDRIVER_PORT
}
if (process.env.WSKNG_NODE_DEBUG) {
// pass WSKNG_DEBUG on to NODE_DEBUG for the application
opts.env.NODE_DEBUG = process.env.WSKNG_NODE_DEBUG
View
@@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "./bin/runLocal.sh"
"test": "./bin/run.sh"
},
"author": "",
"license": "Apache-2.0",
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
ROOTDIR="$SCRIPTDIR/../.."
if [ -z "$WHISKDIR" ]; then
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
ROOTDIR="$SCRIPTDIR/../.."
WHISKDIR="$ROOTDIR/../openwhisk"
fi
@@ -14,7 +15,7 @@ fi
export WHISKDIR
echo "Found WHISKDIR=$WHISKDIR"
DIR=$HOME/.openwhisk-shell/keys
DIR=$ROOTDIR/.openwhisk-shell/keys
mkdir -p $DIR
echo "Made key dir=$DIR"

0 comments on commit a3857fb

Please sign in to comment.