From f9ca62694081f57324cfba65055b5e080fcd832e Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Thu, 5 Apr 2018 10:07:00 -0700 Subject: [PATCH] E2E test for NATS-streaming trigger (#338) E2E test for NATS-streaming trigger: move ad-hoc shell script into CI tests. --- test/mqtrigger/test.sh | 45 ------------------- test/test_utils.sh | 24 ++++++---- test/{ => tests}/mqtrigger/main.js | 0 test/{ => tests}/mqtrigger/stan-pub.go | 0 test/{ => tests}/mqtrigger/stan-sub.go | 0 test/tests/mqtrigger/test_mqtrigger.sh | 61 ++++++++++++++++++++++++++ test/tests/test_pass.sh | 2 + 7 files changed, 78 insertions(+), 54 deletions(-) delete mode 100755 test/mqtrigger/test.sh rename test/{ => tests}/mqtrigger/main.js (100%) rename test/{ => tests}/mqtrigger/stan-pub.go (100%) rename test/{ => tests}/mqtrigger/stan-sub.go (100%) create mode 100755 test/tests/mqtrigger/test_mqtrigger.sh diff --git a/test/mqtrigger/test.sh b/test/mqtrigger/test.sh deleted file mode 100755 index c196252d..00000000 --- a/test/mqtrigger/test.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -set -e - -clusterID="fissionMQTrigger" -topic="foo.bar" -resptopic="foo.foo" -expectedRespOutput="[foo.foo]: 'Hello, World!'" -FISSIONDIR=$GOPATH"/src/github.com/fission/fission" - -if [[ -z $NATS_STREAMING_URL ]]; then - echo "'NATS_STREAMING_URL' must not be empty. For example: export NATS_STREAMING_URL=nats://192.168.0.1:4222" - exit 1 -fi - -if [[ -z $FISSION_URL ]]; then - echo "'FISSION_URL' must not be empty. For example: export FISSION_URL=http://10.10.10.10" - exit 1 -fi - -cd $FISSIONDIR"/fission/" -go build -mv fission $FISSIONDIR"/test/mqtrigger" -cd $FISSIONDIR"/test/mqtrigger" - -./fission env create --name nodejs --image fission/node-env -./fission fn create --name hello1 --env nodejs --code main.js --method GET -./fission route create --method GET --url /h1 --function hello1 -./fission mqtrigger create --name h1 --function hello1 --mqtype "nats-streaming" --topic "foo.bar" --resptopic "foo.foo" - -# wait until nats trigger is created -sleep 5 - -go run ./stan-pub.go -s $NATS_STREAMING_URL -c $clusterID -id clientPub $topic "" || exit 1 - -response=$(go run ./stan-sub.go --last -s $NATS_STREAMING_URL -c $clusterID -id clientSub $resptopic 2>&1) - -if [[ "$response" != "$expectedRespOutput" ]]; then - echo "$response is not equal to $expectedRespOutput" - exit 1 -fi - -echo "Subscriber received expected response: $response" - -exit 0 diff --git a/test/test_utils.sh b/test/test_utils.sh index 0dabbdd0..052c7b92 100755 --- a/test/test_utils.sh +++ b/test/test_utils.sh @@ -161,7 +161,7 @@ helm_install_fission() { controllerNodeport=$6 routerNodeport=$7 fluentdImage=$8 - fluentdImageTag=$9 + fluentdImageTag=${9} pruneInterval="${10}" routerServiceType=${11} @@ -234,15 +234,12 @@ export -f helm_uninstall_fission port_forward_services() { id=$1 ns=f-$id - port=8888 + svc=$2 + port=$3 - kubectl get pods -l svc="router" -o name --namespace $ns | \ + kubectl get pods -l svc="$svc" -o name --namespace $ns | \ sed 's/^.*\///' | \ xargs -I{} kubectl port-forward {} $port:$port -n $ns & - - export FISSION_ROUTER="127.0.0.1:" - FISSION_ROUTER+="$port" - export PATH=$ROOT/fission:$PATH } dump_builder_pod_logs() { @@ -367,6 +364,8 @@ dump_logs() { dump_fission_logs $ns $fns buildermgr dump_fission_logs $ns $fns executor dump_fission_logs $ns $fns storagesvc + dump_fission_logs $ns $fns mqtrigger + dump_fission_logs $ns $fns nats-streaming dump_function_pod_logs $ns $fns dump_builder_pod_logs $bns dump_fission_crds @@ -433,7 +432,7 @@ install_and_test() { routerPort=31235 clean_tpr_crd_resources - + id=$(generate_test_id) trap "helm_uninstall_fission $id" EXIT helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval $routerServiceType @@ -445,7 +444,14 @@ install_and_test() { exit 1 fi - port_forward_services $id $routerPort + export PATH=$ROOT/fission:$PATH + + port_forward_services $id "router" 8888 + port_forward_services $id "nats-streaming" 4222 + + export FISSION_ROUTER="127.0.0.1:8888" + export FISSION_NATS_STREAMING_URL="http://defaultFissionAuthToken@127.0.0.1:4222" + run_all_tests $id dump_logs $id diff --git a/test/mqtrigger/main.js b/test/tests/mqtrigger/main.js similarity index 100% rename from test/mqtrigger/main.js rename to test/tests/mqtrigger/main.js diff --git a/test/mqtrigger/stan-pub.go b/test/tests/mqtrigger/stan-pub.go similarity index 100% rename from test/mqtrigger/stan-pub.go rename to test/tests/mqtrigger/stan-pub.go diff --git a/test/mqtrigger/stan-sub.go b/test/tests/mqtrigger/stan-sub.go similarity index 100% rename from test/mqtrigger/stan-sub.go rename to test/tests/mqtrigger/stan-sub.go diff --git a/test/tests/mqtrigger/test_mqtrigger.sh b/test/tests/mqtrigger/test_mqtrigger.sh new file mode 100755 index 00000000..73dfbdd0 --- /dev/null +++ b/test/tests/mqtrigger/test_mqtrigger.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# +# Create a function and trigger it using NATS +# + +set -euo pipefail +set +x + +ROOT=$(dirname $0)/../.. +DIR=$(dirname $0) + +clusterID="fissionMQTrigger" +topic="foo.bar" +resptopic="foo.foo" +expectedRespOutput="[foo.foo]: 'Hello, World!'" + +log "Pre-test cleanup" +fission env delete --name nodejs || true + +log "Creating nodejs env" +fission env create --name nodejs --image fission/node-env +trap "fission env delete --name nodejs" EXIT + +log "Creating function" +fn=hello-$(date +%s) +fission fn create --name $fn --env nodejs --code $DIR/main.js --method GET +trap "fission fn delete --name $fn" EXIT + +log "Creating message queue trigger" +mqt=mqt-$(date +%s) +fission mqtrigger create --name $mqt --function $fn --mqtype "nats-streaming" --topic $topic --resptopic $resptopic +trap "fission mqtrigger delete --name $mqt" EXIT + +# wait until nats trigger is created +sleep 5 + +# +# Send a message +# +log "Sending message" +go run $DIR/stan-pub.go -s $FISSION_NATS_STREAMING_URL -c $clusterID -id clientPub $topic "" + +# +# Wait for message on response topic +# +log "Waiting for response" +TIMEOUT=timeout +if [ $(uname -s) == 'Darwin' ] +then + # If this fails on mac os, do "brew install coreutils". + TIMEOUT=gtimeout +fi +response=$($TIMEOUT 120s go run $DIR/stan-sub.go --last -s $FISSION_NATS_STREAMING_URL -c $clusterID -id clientSub $resptopic 2>&1) + +if [[ "$response" != "$expectedRespOutput" ]]; then + log "$response is not equal to $expectedRespOutput" + exit 1 +fi + +log "Subscriber received expected response: $response" diff --git a/test/tests/test_pass.sh b/test/tests/test_pass.sh index ecc71aeb..1405a3c0 100755 --- a/test/tests/test_pass.sh +++ b/test/tests/test_pass.sh @@ -6,5 +6,7 @@ set -euo pipefail # have the right environment, that's all. log "Test test, please ignore." + +log $FISSION_NATS_STREAMING_URL log $FISSION_ROUTER which fission