浏览代码

test: add e2e to coverage test

fanmin shi 9 年之前
父节点
当前提交
b5be18a744
共有 1 个文件被更改,包括 23 次插入4 次删除
  1. 23 4
      test

+ 23 - 4
test

@@ -10,7 +10,8 @@
 # PKG=snap ./test
 # PKG=snap ./test
 #
 #
 # Run code coverage 
 # Run code coverage 
-# COVERDIR=coverage PASSES=cov ./test
+# COVERDIR must either be a absolute path or a relative path to the etcd root
+# COVERDIR=coverage PASSES="build_cov cov" ./test
 set -e
 set -e
 
 
 source ./build
 source ./build
@@ -94,21 +95,31 @@ function cov_pass {
 		exit 255
 		exit 255
 	fi
 	fi
 
 
+	if [ ! -f "bin/etcd_test" ]; then
+		echo "etcd_test binary not found"
+		exit 255
+	fi
+
 	mkdir -p "$COVERDIR"
 	mkdir -p "$COVERDIR"
 
 
 	# PKGS_DELIM contains all the core etcd pkgs delimited by ',' which will be profiled for code coverage.
 	# PKGS_DELIM contains all the core etcd pkgs delimited by ',' which will be profiled for code coverage.
 	# Integration tests will generate code coverage for those pkgs 
 	# Integration tests will generate code coverage for those pkgs 
 	PKGS_DELIM=$(echo $TEST | sed 's/ /,/g')
 	PKGS_DELIM=$(echo $TEST | sed 's/ /,/g')
 
 
-	# TODO create coverage to e2e test
 	PKGS=`echo "$TEST_PKGS" | egrep -v "(e2e|functional-tester)"`
 	PKGS=`echo "$TEST_PKGS" | egrep -v "(e2e|functional-tester)"`
-
+	# run code coverage for unit and integration tests
 	for t in ${PKGS}; do
 	for t in ${PKGS}; do
 		tf=`echo $t | tr / _`
 		tf=`echo $t | tr / _`
-		#  uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
+		# uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
 		go test -covermode=set -coverpkg $PKGS_DELIM -timeout 15m -run=Test -v -coverprofile "$COVERDIR/${tf}.coverprofile"  ${REPO_PATH}/$t
 		go test -covermode=set -coverpkg $PKGS_DELIM -timeout 15m -run=Test -v -coverprofile "$COVERDIR/${tf}.coverprofile"  ${REPO_PATH}/$t
 	done
 	done
 
 
+	# run code coverage for e2e tests
+	# use 30m timeout because e2e coverage takes longer 
+	# due to many tests cause etcd process to wait
+	# on leadership transfer timeout during gracefully shutdown
+	go test -tags cov -timeout 30m -v ${REPO_PATH}"/e2e"
+
 	gocovmerge "$COVERDIR"/*.coverprofile >"$COVERDIR"/cover.out
 	gocovmerge "$COVERDIR"/*.coverprofile >"$COVERDIR"/cover.out
 }
 }
 
 
@@ -283,6 +294,14 @@ function dep_pass {
 	fi
 	fi
 }
 }
 
 
+function build_cov_pass {
+	out="bin"
+	if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
+	PKGS=$TEST
+	ETCD_PKGS_DELIM=$(echo $PKGS | sed 's/ /,/g')
+	go test -c -covermode=set -coverpkg=$ETCD_PKGS_DELIM -o ${out}/etcd_test 
+}
+
 function compile_pass {
 function compile_pass {
 	echo "Checking build..."
 	echo "Checking build..."
 	go build -v ./tools/...
 	go build -v ./tools/...