From f197aa8f6a020649dc8091a2ffda1b5ce1f94aae Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 28 Sep 2015 22:46:18 +0200 Subject: [PATCH] Try Circle --- circle.yml | 8 ++++++++ zombietest/Makefile | 16 ++++++++++------ zombietest/test.bash | 27 ++++++++++++++++++++------- 3 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..97109ef --- /dev/null +++ b/circle.yml @@ -0,0 +1,8 @@ +machine: + services: + - docker + +test: + override: + - go test -v + - make CIRCLECI=true SUDO=sudo RM= -C zombietest diff --git a/zombietest/Makefile b/zombietest/Makefile index 757398d..c1d9b19 100644 --- a/zombietest/Makefile +++ b/zombietest/Makefile @@ -1,23 +1,27 @@ +GO?=go +SUDO?= +RM?=--rm + .PHONY: test clean test: .test.uptodate ./test.bash .test.uptodate: runsvinit zombie run-zombie Dockerfile - docker build -t zombietest . + $(SUDO) docker build -t zombietest . touch $@ runsvinit: ../*.go - env GOOS=linux GOARCH=amd64 go build -o $@ github.com/peterbourgon/runsvinit + env GOOS=linux GOARCH=amd64 $(GO) build -o $@ github.com/peterbourgon/runsvinit zombie: .build.uptodate - docker run --rm -v $(shell pwd):/mount zombietest-build cc -Wall -Werror -o /mount/zombie /zombie.c + $(SUDO) docker run $(RM) -v $(shell pwd):/mount zombietest-build cc -Wall -Werror -o /mount/zombie /zombie.c .build.uptodate: build/zombie.c build/Dockerfile - docker build -t zombietest-build build/ + $(SUDO) docker build -t zombietest-build build/ touch $@ clean: rm -rf .test.uptodate .build.uptodate runsvinit zombie - docker stop zombietest zombietest-build >/dev/null 2>&1 || true - docker rm zombietest zombietest-build >/dev/null 2>&1 || true + $(SUDO) docker stop zombietest zombietest-build >/dev/null 2>&1 || true + $(SUDO) docker rm zombietest zombietest-build >/dev/null 2>&1 || true diff --git a/zombietest/test.bash b/zombietest/test.bash index ca04214..f6339d8 100755 --- a/zombietest/test.bash +++ b/zombietest/test.bash @@ -1,11 +1,26 @@ #!/bin/bash -RC=0 +function zombies() { + if [ -z "$CIRCLECI" ] + then + docker exec $C ps -o pid,stat | grep Z | wc -l + else + # https://circleci.com/docs/docker#docker-exec + sudo lxc-attach -n "$(docker inspect --format '{{.Id}}' $C)" -- sh -c "ps -o pid,stat | grep Z | wc -l" + fi +} + +function stop_rm() { + docker stop $1 + docker rm $1 +} + SLEEP=1 +RC=0 C=$(docker run -d zombietest /runsvinit -reap=false) sleep $SLEEP -NOREAP=$(docker exec $C ps -o pid,stat | grep Z | wc -l) +NOREAP=$(zombies) echo -n without reaping, we have $NOREAP zombies... if [ "$NOREAP" -le "0" ] then @@ -14,12 +29,11 @@ then else echo " good" fi -docker stop $C >/dev/null -docker rm $C >/dev/null +stop_rm $C C=$(docker run -d zombietest /runsvinit) sleep $SLEEP -YESREAP=$(docker exec $C ps -o pid,stat | grep Z | wc -l) +YESREAP=$(zombies) echo -n with reaping, we have $YESREAP zombies... if [ "$YESREAP" -gt "0" ] then @@ -28,7 +42,6 @@ then else echo " good" fi -docker stop $C >/dev/null -docker rm $C >/dev/null +stop_rm $C exit $RC