Explorar o código

Merge pull request #8874 from gyuho/release-branch

release-3.2: fix unit test script, remove old tests, backport functional testing data dir commands
Gyu-Ho Lee %!s(int64=8) %!d(string=hai) anos
pai
achega
d5572964e1
Modificáronse 4 ficheiros con 34 adicións e 352 borrados
  1. 1 0
      .gitignore
  2. 1 1
      .semaphore.sh
  3. 0 239
      clientv3/balancer_test.go
  4. 32 112
      test

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
+/agent-*
 /coverage
 /coverage
 /gopath
 /gopath
 /gopath.proto
 /gopath.proto

+ 1 - 1
.semaphore.sh

@@ -13,4 +13,4 @@ docker run \
 	gcr.io/etcd-development/etcd-test:go1.8.5 \
 	gcr.io/etcd-development/etcd-test:go1.8.5 \
 	/bin/bash -c "${TEST_OPTS} ./test 2>&1 | tee test-${TEST_SUFFIX}.log"
 	/bin/bash -c "${TEST_OPTS} ./test 2>&1 | tee test-${TEST_SUFFIX}.log"
 
 
-! egrep "(--- FAIL:|leak)" -A10 -B50 test-${TEST_SUFFIX}.log
+! egrep "(--- FAIL:|panic: test timed out|appears to have leaked|Too many goroutines)" -B50 -A10 test-${TEST_SUFFIX}.log

+ 0 - 239
clientv3/balancer_test.go

@@ -1,239 +0,0 @@
-// Copyright 2016 The etcd Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package clientv3
-
-import (
-	"errors"
-	"net"
-	"sync"
-	"testing"
-	"time"
-
-	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
-	"github.com/coreos/etcd/pkg/testutil"
-
-	"golang.org/x/net/context"
-	"google.golang.org/grpc"
-)
-
-var (
-	endpoints = []string{"localhost:2379", "localhost:22379", "localhost:32379"}
-)
-
-func TestBalancerGetUnblocking(t *testing.T) {
-	sb := newSimpleBalancer(endpoints)
-	defer sb.Close()
-	if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
-		t.Errorf("Initialize newSimpleBalancer should have triggered Notify() chan, but it didn't")
-	}
-	unblockingOpts := grpc.BalancerGetOptions{BlockingWait: false}
-
-	_, _, err := sb.Get(context.Background(), unblockingOpts)
-	if err != ErrNoAddrAvilable {
-		t.Errorf("Get() with no up endpoints should return ErrNoAddrAvailable, got: %v", err)
-	}
-
-	down1 := sb.Up(grpc.Address{Addr: endpoints[1]})
-	if addrs := <-sb.Notify(); len(addrs) != 1 {
-		t.Errorf("first Up() should have triggered balancer to send the first connected address via Notify chan so that other connections can be closed")
-	}
-	down2 := sb.Up(grpc.Address{Addr: endpoints[2]})
-	addrFirst, putFun, err := sb.Get(context.Background(), unblockingOpts)
-	if err != nil {
-		t.Errorf("Get() with up endpoints should success, got %v", err)
-	}
-	if addrFirst.Addr != endpoints[1] {
-		t.Errorf("Get() didn't return expected address, got %v", addrFirst)
-	}
-	if putFun == nil {
-		t.Errorf("Get() returned unexpected nil put function")
-	}
-	addrSecond, _, _ := sb.Get(context.Background(), unblockingOpts)
-	if addrFirst.Addr != addrSecond.Addr {
-		t.Errorf("Get() didn't return the same address as previous call, got %v and %v", addrFirst, addrSecond)
-	}
-
-	down1(errors.New("error"))
-	if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
-		t.Errorf("closing the only connection should triggered balancer to send the all endpoints via Notify chan so that we can establish a connection")
-	}
-	down2(errors.New("error"))
-	_, _, err = sb.Get(context.Background(), unblockingOpts)
-	if err != ErrNoAddrAvilable {
-		t.Errorf("Get() with no up endpoints should return ErrNoAddrAvailable, got: %v", err)
-	}
-}
-
-func TestBalancerGetBlocking(t *testing.T) {
-	sb := newSimpleBalancer(endpoints)
-	defer sb.Close()
-	if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
-		t.Errorf("Initialize newSimpleBalancer should have triggered Notify() chan, but it didn't")
-	}
-	blockingOpts := grpc.BalancerGetOptions{BlockingWait: true}
-
-	ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*100)
-	_, _, err := sb.Get(ctx, blockingOpts)
-	if err != context.DeadlineExceeded {
-		t.Errorf("Get() with no up endpoints should timeout, got %v", err)
-	}
-
-	downC := make(chan func(error), 1)
-
-	go func() {
-		// ensure sb.Up() will be called after sb.Get() to see if Up() releases blocking Get()
-		time.Sleep(time.Millisecond * 100)
-		f := sb.Up(grpc.Address{Addr: endpoints[1]})
-		if addrs := <-sb.Notify(); len(addrs) != 1 {
-			t.Errorf("first Up() should have triggered balancer to send the first connected address via Notify chan so that other connections can be closed")
-		}
-		downC <- f
-	}()
-	addrFirst, putFun, err := sb.Get(context.Background(), blockingOpts)
-	if err != nil {
-		t.Errorf("Get() with up endpoints should success, got %v", err)
-	}
-	if addrFirst.Addr != endpoints[1] {
-		t.Errorf("Get() didn't return expected address, got %v", addrFirst)
-	}
-	if putFun == nil {
-		t.Errorf("Get() returned unexpected nil put function")
-	}
-	down1 := <-downC
-
-	down2 := sb.Up(grpc.Address{Addr: endpoints[2]})
-	addrSecond, _, _ := sb.Get(context.Background(), blockingOpts)
-	if addrFirst.Addr != addrSecond.Addr {
-		t.Errorf("Get() didn't return the same address as previous call, got %v and %v", addrFirst, addrSecond)
-	}
-
-	down1(errors.New("error"))
-	if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
-		t.Errorf("closing the only connection should triggered balancer to send the all endpoints via Notify chan so that we can establish a connection")
-	}
-	down2(errors.New("error"))
-	ctx, _ = context.WithTimeout(context.Background(), time.Millisecond*100)
-	_, _, err = sb.Get(ctx, blockingOpts)
-	if err != context.DeadlineExceeded {
-		t.Errorf("Get() with no up endpoints should timeout, got %v", err)
-	}
-}
-
-// TestBalancerDoNotBlockOnClose ensures that balancer and grpc don't deadlock each other
-// due to rapid open/close conn. The deadlock causes balancer.Close() to block forever.
-// See issue: https://github.com/coreos/etcd/issues/7283 for more detail.
-func TestBalancerDoNotBlockOnClose(t *testing.T) {
-	defer testutil.AfterTest(t)
-
-	kcl := newKillConnListener(t, 3)
-	defer kcl.close()
-
-	for i := 0; i < 5; i++ {
-		sb := newSimpleBalancer(kcl.endpoints())
-		conn, err := grpc.Dial("", grpc.WithInsecure(), grpc.WithBalancer(sb))
-		if err != nil {
-			t.Fatal(err)
-		}
-		kvc := pb.NewKVClient(conn)
-		<-sb.readyc
-
-		var wg sync.WaitGroup
-		wg.Add(100)
-		cctx, cancel := context.WithCancel(context.TODO())
-		for j := 0; j < 100; j++ {
-			go func() {
-				defer wg.Done()
-				kvc.Range(cctx, &pb.RangeRequest{}, grpc.FailFast(false))
-			}()
-		}
-		// balancer.Close() might block
-		// if balancer and grpc deadlock each other.
-		bclosec, cclosec := make(chan struct{}), make(chan struct{})
-		go func() {
-			defer close(bclosec)
-			sb.Close()
-		}()
-		go func() {
-			defer close(cclosec)
-			conn.Close()
-		}()
-		select {
-		case <-bclosec:
-		case <-time.After(3 * time.Second):
-			testutil.FatalStack(t, "balancer close timeout")
-		}
-		select {
-		case <-cclosec:
-		case <-time.After(3 * time.Second):
-			t.Fatal("grpc conn close timeout")
-		}
-
-		cancel()
-		wg.Wait()
-	}
-}
-
-// killConnListener listens incoming conn and kills it immediately.
-type killConnListener struct {
-	wg    sync.WaitGroup
-	eps   []string
-	stopc chan struct{}
-	t     *testing.T
-}
-
-func newKillConnListener(t *testing.T, size int) *killConnListener {
-	kcl := &killConnListener{stopc: make(chan struct{}), t: t}
-
-	for i := 0; i < size; i++ {
-		ln, err := net.Listen("tcp", ":0")
-		if err != nil {
-			t.Fatal(err)
-		}
-		kcl.eps = append(kcl.eps, ln.Addr().String())
-		kcl.wg.Add(1)
-		go kcl.listen(ln)
-	}
-	return kcl
-}
-
-func (kcl *killConnListener) endpoints() []string {
-	return kcl.eps
-}
-
-func (kcl *killConnListener) listen(l net.Listener) {
-	go func() {
-		defer kcl.wg.Done()
-		for {
-			conn, err := l.Accept()
-			select {
-			case <-kcl.stopc:
-				return
-			default:
-			}
-			if err != nil {
-				kcl.t.Fatal(err)
-			}
-			time.Sleep(1 * time.Millisecond)
-			conn.Close()
-		}
-	}()
-	<-kcl.stopc
-	l.Close()
-}
-
-func (kcl *killConnListener) close() {
-	close(kcl.stopc)
-	kcl.wg.Wait()
-}

+ 32 - 112
test

@@ -38,13 +38,13 @@ IGNORE_PKGS="(cmd/|etcdserverpb|rafttest|gopath.proto|v3lockpb|v3electionpb)"
 INTEGRATION_PKGS="(integration|e2e|contrib|functional-tester)"
 INTEGRATION_PKGS="(integration|e2e|contrib|functional-tester)"
 
 
 # all github.com/coreos/etcd/whatever pkgs that are not auto-generated / tools
 # all github.com/coreos/etcd/whatever pkgs that are not auto-generated / tools
-PKGS=`find . -name \*.go | while read a; do dirname $a; done | sort | uniq | egrep -v "$IGNORE_PKGS" | egrep -v "(tools/|contrib/|e2e|pb)" | sed "s|\.|${REPO_PATH}|g" | xargs echo`
+PKGS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -vE "(tools/|contrib/|e2e|pb)" | sed "s|\.|${REPO_PATH}|g" | xargs echo)
 # pkg1,pkg2,pkg3
 # pkg1,pkg2,pkg3
 PKGS_COMMA=${PKGS// /,}
 PKGS_COMMA=${PKGS// /,}
 
 
-TEST_PKGS=`find . -name \*_test.go | while read a; do dirname $a; done | sort | uniq | egrep -v "$IGNORE_PKGS" | sed "s|\./||g"`
-FORMATTABLE=`find . -name \*.go | while read a; do echo "$(dirname $a)/*.go"; done | sort | uniq | egrep -v "$IGNORE_PKGS" | sed "s|\./||g"`
-TESTABLE_AND_FORMATTABLE=`echo "$TEST_PKGS" | egrep -v "$INTEGRATION_PKGS"`
+TEST_PKGS=$(find . -name \*_test.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
+FORMATTABLE=$(find . -name \*.go | while read -r a; do echo "$(dirname "$a")/*.go"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | sed "s|\./||g")
+TESTABLE_AND_FORMATTABLE=$(echo "$TEST_PKGS" | grep -vE "$INTEGRATION_PKGS")
 
 
 # check if user provided PKG override
 # check if user provided PKG override
 if [ -z "${USERPKG}" ]; then
 if [ -z "${USERPKG}" ]; then
@@ -58,20 +58,23 @@ else
 	# only run gofmt on packages provided by user
 	# only run gofmt on packages provided by user
 	FMT="$TEST"
 	FMT="$TEST"
 fi
 fi
+FMT=($FMT)
 
 
-# split TEST into an array and prepend REPO_PATH to each local package
-split=(${TEST// / })
-TEST=${split/#/${REPO_PATH}/}
+# prepend REPO_PATH to each local package
+split=$TEST
+TEST=""
+for a in $split; do TEST="$TEST ${REPO_PATH}/${a}"; done
+TEST=($TEST)
 
 
 # TODO: 'client' pkg fails with gosimple from generated files
 # TODO: 'client' pkg fails with gosimple from generated files
 # TODO: 'rafttest' is failing with unused
 # TODO: 'rafttest' is failing with unused
-STATIC_ANALYSIS_PATHS=`find . -name \*.go | while read a; do dirname $a; done | sort | uniq | egrep -v "$IGNORE_PKGS" | grep -v 'client'`
+STATIC_ANALYSIS_PATHS=$(find . -name \*.go | while read -r a; do dirname "$a"; done | sort | uniq | grep -vE "$IGNORE_PKGS" | grep -v 'client')
+STATIC_ANALYSIS_PATHS=($STATIC_ANALYSIS_PATHS)
 
 
 if [ -z "$GOARCH" ]; then
 if [ -z "$GOARCH" ]; then
 	GOARCH=$(go env GOARCH);
 	GOARCH=$(go env GOARCH);
 fi
 fi
 
 
-
 # determine whether target supports race detection
 # determine whether target supports race detection
 if [ "$GOARCH" == "amd64" ]; then
 if [ "$GOARCH" == "amd64" ]; then
 	RACE="--race"
 	RACE="--race"
@@ -79,8 +82,16 @@ fi
 
 
 function unit_pass {
 function unit_pass {
 	echo "Running unit tests..."
 	echo "Running unit tests..."
+	GO_TEST_FLAG=""
+	if [ "${VERBOSE}" == "1" ]; then
+		GO_TEST_FLAG="-v"
+	fi
+	if [ "${VERBOSE}" == "2" ]; then
+		GO_TEST_FLAG="-v"
+		export CLIENT_DEBUG=1
+	fi
 	# only -run=Test so examples can run in integration tests
 	# only -run=Test so examples can run in integration tests
-	go test -timeout 3m ${COVER} ${RACE} -cpu 1,2,4 -run=Test $@ ${TEST}
+	go test ${GO_TEST_FLAG} -timeout 5m "${COVER}" ${RACE} -cpu 1,2,4 -run=Test "$@" "${TEST[@]}"
 }
 }
 
 
 function integration_pass {
 function integration_pass {
@@ -93,6 +104,9 @@ function integration_pass {
 }
 }
 
 
 function functional_pass {
 function functional_pass {
+  	# Clean up any data and logs from previous runs
+  	rm -rf ./agent-*
+
 	for a in 1 2 3; do
 	for a in 1 2 3; do
 		mkdir -p ./agent-$a
 		mkdir -p ./agent-$a
 		./bin/etcd-agent -etcd-path ./bin/etcd -etcd-log-dir "./agent-$a" -port ":${a}9027" -use-root=false &
 		./bin/etcd-agent -etcd-path ./bin/etcd -etcd-log-dir "./agent-$a" -port ":${a}9027" -use-root=false &
@@ -121,7 +135,6 @@ function functional_pass {
 	echo "Waiting for processes to exit"
 	echo "Waiting for processes to exit"
 	kill -s TERM ${agent_pids}
 	kill -s TERM ${agent_pids}
 	for a in ${agent_pids}; do wait $a || true; done
 	for a in ${agent_pids}; do wait $a || true; done
-	rm -rf ./agent-*
 
 
 	if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
 	if [[ "${ETCD_TESTER_EXIT_CODE}" -ne "0" ]]; then
 		echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
 		echo "--- FAIL: exit code" ${ETCD_TESTER_EXIT_CODE}
@@ -129,79 +142,26 @@ function functional_pass {
 	fi
 	fi
 }
 }
 
 
-function cov_pass {
-	echo "Running code coverage..."
-	# install gocovmerge before running code coverage from github.com/wadey/gocovmerge
-	# gocovmerge merges coverage files
-	if ! which gocovmerge >/dev/null; then
-		echo "gocovmerge not installed"
-		exit 255
-	fi
-
-	if [ -z "$COVERDIR" ]; then
-		echo "COVERDIR undeclared"
-		exit 255
-	fi
-
-	if [ ! -f "bin/etcd_test" ]; then
-		echo "etcd_test binary not found"
-		exit 255
-	fi
-
-	mkdir -p "$COVERDIR"
-
-	# run code coverage for unit and integration tests
-	GOCOVFLAGS="-covermode=set -coverpkg $PKGS_COMMA -v -timeout 15m"
-	failed=""
-	for t in `echo "${TEST_PKGS}" | egrep -v "(e2e|functional-tester)"`; do
-		tf=`echo $t | tr / _`
-		# cache package compilation data for faster repeated builds
-		go test $GOCOVFLAGS -i ${REPO_PATH}/$t || true
-		# uses -run=Test to skip examples because clientv3/ example tests will leak goroutines
-		go test $GOCOVFLAGS -run=Test -coverprofile "$COVERDIR/${tf}.coverprofile"  ${REPO_PATH}/$t || failed="$failed $t"
-	done
-
-	# proxy tests
-	go test -tags cluster_proxy $GOCOVFLAGS -coverprofile "$COVERDIR/proxy_integration.coverprofile" ${REPO_PATH}/integration || failed="$failed proxy-integration"
-	go test -tags cluster_proxy $GOCOVFLAGS -coverprofile "$COVERDIR/proxy_clientv3.coverprofile" ${REPO_PATH}/clientv3/integration || failed="$failed proxy-clientv3/integration"
-
-	# 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" || failed="$failed e2e"
-
-	gocovmerge "$COVERDIR"/*.coverprofile >"$COVERDIR"/cover.out
-	# strip out generated files (using GNU-style sed)
-	sed --in-place '/generated.go/d' "$COVERDIR"/cover.out || true
-
-	# held failures to generate the full coverage file, now fail
-	if [ -n "$failed" ]; then
-		for f in $failed; do
-			echo "--- FAIL:" "$f"
-		done
-		exit 255
-	fi
-}
-
 function e2e_pass {
 function e2e_pass {
 	echo "Running e2e tests..."
 	echo "Running e2e tests..."
 	go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e
 	go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e
 }
 }
 
 
+function integration_extra {
+	go test -timeout 15m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/client/integration"
+	go test -timeout 15m -v ${RACE} -cpu 1,2,4 "$@" "${REPO_PATH}/clientv3/integration"
+}
+
 function integration_e2e_pass {
 function integration_e2e_pass {
 	echo "Running integration and e2e tests..."
 	echo "Running integration and e2e tests..."
 
 
-	go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/e2e &
+	go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/e2e" &
 	e2epid="$!"
 	e2epid="$!"
-	go test -timeout 15m -v -cpu 1,2,4 $@ ${REPO_PATH}/integration &
+	go test -timeout 15m -v -cpu 1,2,4 "$@" "${REPO_PATH}/integration" &
 	intpid="$!"
 	intpid="$!"
 	wait $e2epid
 	wait $e2epid
 	wait $intpid
 	wait $intpid
-	go test -timeout 1m -v ${RACE} -cpu 1,2,4 $@ ${REPO_PATH}/client/integration
-	go test -timeout 10m -v ${RACE} -cpu 1,2,4 $@ ${REPO_PATH}/clientv3/integration
-	go test -timeout 1m -v -cpu 1,2,4 $@ ${REPO_PATH}/contrib/raftexample
-	go test -timeout 1m -v ${RACE} -cpu 1,2,4 -run=Example $@ ${TEST}
+	integration_extra "$@"
 }
 }
 
 
 function grpcproxy_pass {
 function grpcproxy_pass {
@@ -258,30 +218,6 @@ function fmt_pass {
 		exit 255
 		exit 255
 	fi
 	fi
 
 
-	echo "Checking 'go tool vet -all -shadow'..."
-	fmtpkgs=$(echo $FMT | xargs dirname | sort | uniq | sed '/\./d')
-	vetRes=$(go tool vet -all -shadow ${fmtpkgs} 2>&1 | grep -v '/gw/' || true)
-	if [ -n "${vetRes}" ]; then
-		echo -e "govet -all -shadow checking failed:\n${vetRes}"
-		exit 255
-	fi
-
-	if which shellcheck >/dev/null; then
-		echo "Checking shellcheck..."
-		shellcheckResult=$(shellcheck -fgcc build test scripts/* 2>&1 || true)
-		if [ -n "${shellcheckResult}" ]; then
-			# mask the most common ones; fix later
-			SHELLCHECK_MASK="SC(2086|2006|2068|2196|2035|2162|2076)"
-			errs=$(echo "${shellcheckResult}" | egrep -v "${SHELLCHECK_MASK}" || true)
-			if [ -n "${errs}" ]; then
-				echo -e "shellcheck checking failed:\n${shellcheckResult}\n===\nFailed:\n${errs}"
-				exit 255
-			fi
-			suppressed=$(echo "${shellcheckResult}" | cut -f4- -d':' | sort | uniq -c | sort -n)
-			echo -e "shellcheck suppressed warnings:\n${suppressed}"
-		fi
-	fi
-
 	echo "Checking documentation style..."
 	echo "Checking documentation style..."
 	# eschew you
 	# eschew you
 	yous=`find . -name \*.md -exec egrep --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true`
 	yous=`find . -name \*.md -exec egrep --color "[Yy]ou[r]?[ '.,;]" {} + | grep -v /v2/ || true`
@@ -302,22 +238,6 @@ function fmt_pass {
 		echo "Skipping marker..."
 		echo "Skipping marker..."
 	fi
 	fi
 
 
-	if which goword >/dev/null; then
-		echo "Checking goword..."
-		# get all go files to process
-		gofiles=`find $FMT -iname '*.go' 2>/dev/null`
-		# ignore tests and protobuf files
-		gofiles=`echo ${gofiles} | sort | uniq | sed "s/ /\n/g" | egrep -v "(\\_test.go|\\.pb\\.go)"`
-		# only check for broken exported godocs
-		gowordRes=`goword -use-spell=false ${gofiles} | grep godoc-export | sort`
-		if [ ! -z "$gowordRes" ]; then
-			echo -e "goword checking failed:\n${gowordRes}"
-			exit 255
-		fi
-	else
-		echo "Skipping goword..."
-	fi
-
 	if which gosimple >/dev/null; then
 	if which gosimple >/dev/null; then
 		echo "Checking gosimple..."
 		echo "Checking gosimple..."
 		gosimpleResult=`gosimple ${STATIC_ANALYSIS_PATHS} 2>&1 || true`
 		gosimpleResult=`gosimple ${STATIC_ANALYSIS_PATHS} 2>&1 || true`