From c63a427ca344e9dbba5bfe9c33027f7ecf9cd7dc Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Wed, 20 Sep 2017 06:51:56 -0700 Subject: [PATCH] Fix internal route setup bug (#335) Fixes #334 which broke internal routes, and adds a test. --- router/httpTriggers.go | 3 +- test/tests/test_internal_routes.sh | 46 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 test/tests/test_internal_routes.sh diff --git a/router/httpTriggers.go b/router/httpTriggers.go index 40c7a382..93301a97 100644 --- a/router/httpTriggers.go +++ b/router/httpTriggers.go @@ -115,9 +115,10 @@ func (ts *HTTPTriggerSet) getRouter() *mux.Router { // Internal triggers for each function by name. Non-http // triggers route into these. for _, function := range ts.functions { + m := function.Metadata fh := &functionHandler{ fmap: ts.functionServiceMap, - function: &function.Metadata, + function: &m, poolmgr: ts.poolmgr, } muxRouter.HandleFunc(fission.UrlForFunction(function.Metadata.Name), fh.handler) diff --git a/test/tests/test_internal_routes.sh b/test/tests/test_internal_routes.sh new file mode 100755 index 00000000..07801683 --- /dev/null +++ b/test/tests/test_internal_routes.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# +# Create two functions, make sure their internal http triggers invoke +# them correctly. +# + +set -euo pipefail + +ROOT=$(dirname $0)/../.. + +echo "Pre-test cleanup" +fission env delete --name nodejs || true + +echo "Creating nodejs env" +fission env create --name nodejs --image fission/node-env +trap "fission env delete --name nodejs" EXIT + +echo "Writing functions" +f1=f1-$(date +%s) +f2=f2-$(date +%s) +echo $f1 $f2 + +for f in $f1 $f2 +do + echo "module.exports = function(context, callback) { callback(200, \"$f\n\"); }" > $f.js +done + +echo "Creating functions" +for f in $f1 $f2 +do + fission fn create --name $f --env nodejs --code $f.js + trap "fission fn delete --name $f" EXIT +done + +echo "Waiting for router to catch up" +sleep 3 + +echo "Testing internal routes" +for f in $f1 $f2 +do + response=$(curl http://$FISSION_ROUTER/fission-function/$f) + echo $response | grep $f +done + +echo "All done."