E2E test for NATS-streaming trigger (#338)
E2E test for NATS-streaming trigger: move ad-hoc shell script into CI tests.
This commit is contained in:
@@ -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
|
|
||||||
+15
-9
@@ -161,7 +161,7 @@ helm_install_fission() {
|
|||||||
controllerNodeport=$6
|
controllerNodeport=$6
|
||||||
routerNodeport=$7
|
routerNodeport=$7
|
||||||
fluentdImage=$8
|
fluentdImage=$8
|
||||||
fluentdImageTag=$9
|
fluentdImageTag=${9}
|
||||||
pruneInterval="${10}"
|
pruneInterval="${10}"
|
||||||
routerServiceType=${11}
|
routerServiceType=${11}
|
||||||
|
|
||||||
@@ -234,15 +234,12 @@ export -f helm_uninstall_fission
|
|||||||
port_forward_services() {
|
port_forward_services() {
|
||||||
id=$1
|
id=$1
|
||||||
ns=f-$id
|
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/^.*\///' | \
|
sed 's/^.*\///' | \
|
||||||
xargs -I{} kubectl port-forward {} $port:$port -n $ns &
|
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() {
|
dump_builder_pod_logs() {
|
||||||
@@ -367,6 +364,8 @@ dump_logs() {
|
|||||||
dump_fission_logs $ns $fns buildermgr
|
dump_fission_logs $ns $fns buildermgr
|
||||||
dump_fission_logs $ns $fns executor
|
dump_fission_logs $ns $fns executor
|
||||||
dump_fission_logs $ns $fns storagesvc
|
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_function_pod_logs $ns $fns
|
||||||
dump_builder_pod_logs $bns
|
dump_builder_pod_logs $bns
|
||||||
dump_fission_crds
|
dump_fission_crds
|
||||||
@@ -433,7 +432,7 @@ install_and_test() {
|
|||||||
routerPort=31235
|
routerPort=31235
|
||||||
|
|
||||||
clean_tpr_crd_resources
|
clean_tpr_crd_resources
|
||||||
|
|
||||||
id=$(generate_test_id)
|
id=$(generate_test_id)
|
||||||
trap "helm_uninstall_fission $id" EXIT
|
trap "helm_uninstall_fission $id" EXIT
|
||||||
helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval $routerServiceType
|
helm_install_fission $id $image $imageTag $fetcherImage $fetcherImageTag $controllerPort $routerPort $fluentdImage $fluentdImageTag $pruneInterval $routerServiceType
|
||||||
@@ -445,7 +444,14 @@ install_and_test() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
run_all_tests $id
|
||||||
|
|
||||||
dump_logs $id
|
dump_logs $id
|
||||||
|
|||||||
Executable
+61
@@ -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"
|
||||||
@@ -6,5 +6,7 @@ set -euo pipefail
|
|||||||
# have the right environment, that's all.
|
# have the right environment, that's all.
|
||||||
|
|
||||||
log "Test test, please ignore."
|
log "Test test, please ignore."
|
||||||
|
|
||||||
|
log $FISSION_NATS_STREAMING_URL
|
||||||
log $FISSION_ROUTER
|
log $FISSION_ROUTER
|
||||||
which fission
|
which fission
|
||||||
|
|||||||
Reference in New Issue
Block a user