Skip to content

Commit

Permalink
test: add integration test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: letty <[email protected]>
  • Loading branch information
Letty5411 committed May 22, 2018
1 parent 1a982bf commit 8cbc904
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ env:

script:
- sudo make -e ${TEST_SUITE}

after_success:
- bash <(curl -s https://codecov.io/bash) || echo Codecov_Did_Not_Collect_Coverage_Reports
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ server: pre modules
client: pre
@./hack/build client

.PHONY: testserver
testserver: pre modules
@./hack/build testserver

.PHONY: clean
clean:
$(GOCLEAN)
Expand Down
34 changes: 33 additions & 1 deletion hack/build
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ function client()
$GOBUILD -o $CLI_BINARY_NAME github.com/alibaba/pouch/cli
}

#
# Do not calculate the coverage for the following pkgs
#
SKIP_PKGS=(\
"github.com/alibaba/pouch/vendor" \
"github.com/alibaba/pouch/extra" \
"github.com/alibaba/pouch/test" \
"github.com/alibaba/pouch/apis/types" \
"github.com/alibaba/pouch/cri/config" \
"github.com/alibaba/pouch/storage/volume/examples/demo" \
"github.com/alibaba/pouch/storage/volume/types" \
)

function testserver()
{
cd $BUILDPATH/src/github.com/alibaba/pouch
cmd="go list ./... "
for j in $(seq 0 $(( ${#SKIP_PKGS[@]} -1)) ); do
cmd+="| grep -v \"${SKIP_PKGS[$j]}\" "
done

pkgs=$(eval $cmd |grep -v 'github.com/alibaba/pouch/cli' | tr '\n' ','|sed 's/,$//g')

go test -c -race -cover -covermode=atomic -o pouchd-test -coverpkg $pkgs
}

function vet()
{
cd $BUILDPATH/src/github.com/alibaba/pouch
Expand All @@ -58,7 +84,13 @@ function unit-test()
{
cd $BUILDPATH/src/github.com/alibaba/pouch
go test -i
for d in `go list ./... | grep -v 'github.com/alibaba/pouch/test' | grep -v 'github.com/alibaba/pouch/extra' | grep -v 'github.com/alibaba/pouch/vendor' `

cmd="go list ./... "
for j in $(seq 0 $(( ${#SKIP_PKGS[@]} -1)) ); do
cmd+="| grep -v \"${SKIP_PKGS[$j]}\" "
done

for d in $(eval $cmd |grep -vw '^github.com/alibaba/pouch$' )
do
go test -race -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ] ; then
Expand Down
60 changes: 55 additions & 5 deletions hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ if [[ $SOURCEDIR != $DIR ]];then
ln -sf $DIR/ $SOURCEDIR
fi

#
# CAL_INTEGRATION_TEST_COVERAGE indicates whehter or not calculate integration test coverage.
# By default it is yes.
#
CAL_INTEGRATION_TEST_COVERAGE=${CAL_INTEGRATION_TEST_COVERAGE:-"yes"}
if [[ $CAL_INTEGRATION_TEST_COVERAGE == "yes" ]]; then
POUCHD="pouchd-test -test.coverprofile=$DIR/integrationcover.out DEVEL"
else
POUCHD="pouchd"
fi

function get_containerd_version
{
if which containerd &>/dev/null; then
Expand Down Expand Up @@ -157,6 +168,9 @@ function install_pouch
install_runc
# copy pouch daemon and pouch cli to PATH
echo "Install pouch."
if [[ $CAL_INTEGRATION_TEST_COVERAGE == "yes" ]]; then
cp -f $DIR/pouchd-test /usr/local/bin/
fi
cp -f $DIR/pouch $DIR/pouchd /usr/local/bin/
install_lxcfs
install_nsenter
Expand All @@ -169,9 +183,19 @@ function target
docker run --rm -v $(pwd):$SOURCEDIR $IMAGE bash -c "make check"
;;
build)
#
# Also build pouchd-test binary if CAL_INTEGRATION_TEST_COVERAGE doesn't
# equal to 'no'.
#
if [[ $CAL_INTEGRATION_TEST_COVERAGE == "yes" ]]; then
docker run --rm -v $(pwd):$SOURCEDIR $IMAGE \
bash -c "make testserver" >$TMP/build.log ||
{ echo "make build log:"; cat $TMP/build.log; return 1; }
fi
docker run --rm -v $(pwd):$SOURCEDIR $IMAGE \
bash -c "make build" >$TMP/build.log ||
{ echo "make build log:"; cat $TMP/build.log; return 1; }

install_pouch >$TMP/install.log ||
{ echo "install pouch log:"; cat $TMP/install.log; return 1; }
;;
Expand All @@ -184,10 +208,11 @@ function target
env PATH=$GOROOT/bin:$PATH $SOURCEDIR/hack/cri-test/test-cri.sh
;;
integration-test)

install_dumb_init ||
echo "Warning: dumb-init install failed!\
rich container related tests will be skipped"

docker run --rm -v $(pwd):$SOURCEDIR \
-e GOPATH=/go:$SOURCEDIR/extra/libnetwork/Godeps/_workspace \
$IMAGE \
Expand All @@ -196,10 +221,10 @@ function target
#start pouch daemon
echo "start pouch daemon"
if stat /usr/bin/lxcfs ; then
pouchd --debug --enable-lxcfs=true \
$POUCHD --debug --enable-lxcfs=true \
--lxcfs=/usr/bin/lxcfs > $TMP/log 2>&1 &
else
pouchd --debug > $TMP/log 2>&1 &
$POUCHD --debug > $TMP/log 2>&1 &
fi

# wait until pouch daemon is ready
Expand All @@ -226,8 +251,14 @@ function target
cp -rf $DIR/test/tls /tmp/

# If test is failed, print pouch daemon log.
$DIR/test/integration-test -test.v -check.v ||
{ echo "pouch daemon log:"; cat $TMP/log; return 1; }
set +e
$DIR/test/integration-test -test.v -check.v
if (( $? != 0 )); then
echo "pouch daemon log:"
cat $TMP/log
return 1
fi
set -e
;;
*)
echo "no such target: $target"
Expand All @@ -253,7 +284,26 @@ function main

for target in ${targets[@]}; do
target $target
ret=$?
if (( $ret != 0 )); then
return $ret
fi
done

if [[ $CAL_INTEGRATION_TEST_COVERAGE == "yes" ]]; then
if ! echo ${targets[@]} | grep -q "integration" ; then
return $ret
fi
#
# kill pouchd-test and get the coverage
#
pkill --signal 3 pouchd-test || echo "no pouchd-test to be killed"
sleep 5

tail -1 $TMP/log
cat $DIR/integrationcover.out >> $DIR/coverage.txt
return $ret
fi
}

main "$@"
41 changes: 41 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"os"
"os/signal"
"strings"
"syscall"
"testing"
)

func TestMain(t *testing.T) {
var (
args []string
)

for _, arg := range os.Args {
switch {
case strings.HasPrefix(arg, "DEVEL"):
case strings.HasPrefix(arg, "-test"):
default:
args = append(args, arg)
}
}

waitCh := make(chan int, 1)

os.Args = args
go func() {
main()
close(waitCh)
}()

signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
select {
case <-signalCh:
return
case <-waitCh:
return
}
}
1 change: 1 addition & 0 deletions test/api_container_exec_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (suite *APIContainerExecInspectSuite) SetUpTest(c *check.C) {

// TestContainerCreateExecOk tests execing containers is OK.
func (suite *APIContainerExecInspectSuite) TestContainerExecInspectOk(c *check.C) {
c.Skip("skip flaky test due to issue#1372")
cname := "TestContainerExecInspectOk"

CreateBusyboxContainerOk(c, cname)
Expand Down

0 comments on commit 8cbc904

Please sign in to comment.