From 6fe69590c4d9f1d79554e2c0ea2a7500ac3acaf0 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 28 Jul 2015 14:57:45 +0000 Subject: [PATCH] Add coverage to proxy for integration tests. --- Makefile | 6 +++--- prog/weaveproxy/main.go | 3 ++- prog/weaveproxy/main_test.go | 12 ++++++++++++ test/690_proxy_autoconfig_test.sh | 2 +- test/config.sh | 11 +++++++---- weave | 6 +++--- 6 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 prog/weaveproxy/main_test.go diff --git a/Makefile b/Makefile index 3f93170b..3186f74a 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,6 @@ WEAVE_EXPORT=weave.tar WEAVEEXEC_DOCKER_VERSION=1.3.1 DOCKER_DISTRIB=prog/weaveexec/docker-$(WEAVEEXEC_DOCKER_VERSION).tgz DOCKER_DISTRIB_URL=https://get.docker.com/builds/Linux/x86_64/docker-$(WEAVEEXEC_DOCKER_VERSION).tgz -COVERAGE_MODULES=$(shell go list -f '{{join .Deps "\n"}}' ./prog/weaver | grep "weaveworks" | paste -s -d,) NETGO_CHECK=@strings $@ | grep cgo_stub\\\.go >/dev/null || { \ rm $@; \ echo "\nYour go standard library was built without the 'netgo' build tag."; \ @@ -50,8 +49,9 @@ travis: $(EXES) update: go get -u -f -v -tags -netgo $(addprefix ./,$(dir $(EXES))) -$(WEAVER_EXE): common/*.go common/*/*.go net/*.go +$(WEAVER_EXE) $(WEAVEPROXY_EXE): common/*.go common/*/*.go net/*.go ifeq ($(COVERAGE),true) + $(eval COVERAGE_MODULES := $(shell (go list ./$(@D); go list -f '{{join .Deps "\n"}}' ./$(@D) | grep "weaveworks") | paste -s -d,)) go get -t -tags netgo ./$(@D) go test -c -o ./$@ -ldflags "-extldflags \"-static\" -X main.version $(WEAVE_VERSION)" \ -tags netgo -v -covermode=atomic -coverpkg $(COVERAGE_MODULES) ./$(@D)/ @@ -61,7 +61,7 @@ else endif $(NETGO_CHECK) -$(WEAVEPROXY_EXE) $(NETCHECK_EXE): common/*.go common/*/*.go net/*.go +$(NETCHECK_EXE): common/*.go common/*/*.go net/*.go go get -tags netgo ./$(@D) go build -ldflags "-extldflags \"-static\" -X main.version $(WEAVE_VERSION)" -tags netgo -o $@ ./$(@D) $(NETGO_CHECK) diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index f77f0406..205779b8 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -82,5 +82,6 @@ func main() { Log.Fatalf("Could not start proxy: %s", err) } - p.ListenAndServe() + go p.ListenAndServe() + SignalHandlerLoop() } diff --git a/prog/weaveproxy/main_test.go b/prog/weaveproxy/main_test.go new file mode 100644 index 00000000..1873f4a3 --- /dev/null +++ b/prog/weaveproxy/main_test.go @@ -0,0 +1,12 @@ +package main + +import ( + "testing" + + weavetest "github.com/weaveworks/weave/testing" +) + +func TestMain(t *testing.T) { + weavetest.TrimTestArgs() + main() +} diff --git a/test/690_proxy_autoconfig_test.sh b/test/690_proxy_autoconfig_test.sh index a59d3fc0..5e645735 100755 --- a/test/690_proxy_autoconfig_test.sh +++ b/test/690_proxy_autoconfig_test.sh @@ -5,7 +5,7 @@ start_suite "Boot the proxy should only listen on client's interface" # Booting it over unix socket listens on unix socket -run_on $HOST1 sudo weave launch-proxy +run_on $HOST1 COVERAGE=$COVERAGE sudo -E weave launch-proxy assert_raises "run_on $HOST1 sudo docker -H unix:///var/run/weave.sock ps" assert_raises "proxy docker_on $HOST1 ps" 1 weave_on $HOST1 stop-proxy diff --git a/test/config.sh b/test/config.sh index 1d5871cb..0cb0b8a6 100644 --- a/test/config.sh +++ b/test/config.sh @@ -117,8 +117,10 @@ stop_router_on() { # the weave container, which means we a) can't grab coverage # stats, and b) can't inspect the logs when tests fail. docker_on $host stop weave 1>/dev/null 2>&1 || true + docker_on $host stop weaveproxy 1>/dev/null 2>&1 || true if [ -n "$COVERAGE" ] ; then - collect_coverage $host + collect_coverage $host weave + collect_coverage $host weaveproxy fi } @@ -207,11 +209,12 @@ end_suite() { collect_coverage() { host=$1 + container=$2 mkdir -p ./coverage - rm -f cover.router.prof - docker_on $host cp weave:/home/weave/cover.router.prof . 2>/dev/null || return 0 + rm -f cover.prof + docker_on $host cp $container:/home/weave/cover.prof . 2>/dev/null || return 0 # ideally we'd know the name of the test here, and put that in the filename - mv cover.router.prof $(mktemp -u ./coverage/integration.XXXXXXXX) || true + mv cover.prof $(mktemp -u ./coverage/integration.XXXXXXXX) || true } WEAVE=$DIR/../weave diff --git a/weave b/weave index 55c90a8f..98c95732 100755 --- a/weave +++ b/weave @@ -199,7 +199,7 @@ PROXY_PORT=12375 PROXY_CONTAINER_NAME=weaveproxy COVERAGE_ARGS="" if [ -n "$COVERAGE" ] ; then - COVERAGE_ARGS="-test.coverprofile=/home/weave/cover.router.prof --" + COVERAGE_ARGS="-test.coverprofile=/home/weave/cover.prof --" fi ###################################################################### @@ -433,7 +433,7 @@ ask_version() { fi fi VERSION_COVERAGE_ARGS="" - if [ "$1" = "$CONTAINER_NAME" ] ; then + if [ "$1" = "$CONTAINER_NAME" ] || [ "$1" == "$PROXY_CONTAINER_NAME"] ; then VERSION_COVERAGE_ARGS="$COVERAGE_ARGS" fi [ -n "$DOCKERIMAGE" ] && docker run --rm -e WEAVE_CIDR=none $DOCKERIMAGE $VERSION_COVERAGE_ARGS --version @@ -1137,7 +1137,7 @@ launch_proxy() { -e WEAVE_CIDR=none \ -e DOCKER_BRIDGE \ --entrypoint=/home/weave/weaveproxy \ - $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS) + $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS) wait_for_log $PROXY_CONTAINER_NAME "proxy listening" }