diff --git a/pkg/osutil/signal.go b/pkg/osutil/signal.go index 0e42b9c35f4..154f88204dd 100644 --- a/pkg/osutil/signal.go +++ b/pkg/osutil/signal.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !linux || cov +//go:build !linux package osutil diff --git a/pkg/osutil/signal_linux.go b/pkg/osutil/signal_linux.go index 766ed26f307..a392de83dfe 100644 --- a/pkg/osutil/signal_linux.go +++ b/pkg/osutil/signal_linux.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux && !cov +//go:build linux package osutil diff --git a/scripts/codecov_upload.sh b/scripts/codecov_upload.sh index 8ee1a65afb8..b516b3bf1cb 100755 --- a/scripts/codecov_upload.sh +++ b/scripts/codecov_upload.sh @@ -8,7 +8,7 @@ set -o pipefail LOG_FILE=${1:-test-coverage.log} # We collect the coverage -COVERDIR=covdir PASSES='build build_cov cov' ./scripts/test.sh 2>&1 | tee "${LOG_FILE}" +COVERDIR=covdir PASSES='build cov' ./scripts/test.sh 2>&1 | tee "${LOG_FILE}" test_success="$?" # We try to upload whatever we have: diff --git a/scripts/test.sh b/scripts/test.sh index 991994f2aaf..9e74b993127 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -29,7 +29,7 @@ # # Run code coverage # COVERDIR must either be a absolute path or a relative path to the etcd root -# $ COVERDIR=coverage PASSES="build build_cov cov" ./scripts/test.sh +# $ COVERDIR=coverage PASSES="build cov" ./scripts/test.sh # $ go tool cover -html ./coverage/cover.out set -e @@ -171,13 +171,6 @@ function grpcproxy_e2e_pass { ################# COVERAGE ##################################################### -# Builds artifacts used by tests/e2e in coverage mode. -function build_cov_pass { - run_for_module "server" run go test -tags cov -c -covermode=set -coverpkg="./..." -o "../bin/etcd_test" || return $? - run_for_module "etcdctl" run go test -tags cov -c -covermode=set -coverpkg="./..." -o "../bin/etcdctl_test" || return $? - run_for_module "etcdutl" run go test -tags cov -c -covermode=set -coverpkg="./..." -o "../bin/etcdutl_test" -} - # pkg_to_coverflag [prefix] [pkgs] # produces name of .coverprofile file to be used for tests of this package function pkg_to_coverprofileflag { @@ -264,11 +257,6 @@ function cov_pass { return 255 fi - if [ ! -f "bin/etcd_test" ]; then - log_error "etcd_test binary not found. Call: PASSES='build_cov' ./scripts/test.sh" - return 255 - fi - local coverdir coverdir=$(readlink -f "${COVERDIR}") mkdir -p "${coverdir}" @@ -298,18 +286,6 @@ function cov_pass { run_for_module "tests" go_test "./integration/..." "parallel" "pkg_to_coverprofileflag integration_cluster_proxy" \ -tags cluster_proxy -timeout=30m "${gocov_build_flags[@]}" || failed="$failed integration_cluster_proxy" - log_callout "[$(date)] Collecting coverage from e2e tests ..." - # We don't pass 'gocov_build_flags' nor 'pkg_to_coverprofileflag' here, - # as the coverage is collected from the ./bin/etcd_test & ./bin/etcdctl_test internally spawned. - mkdir -p "${coverdir}/e2e" - COVERDIR="${coverdir}/e2e" run_for_module "tests" go_test "./e2e/..." "keep_going" : -tags=cov -timeout 30m "$@" || failed="$failed tests_e2e" - split_dir "${coverdir}/e2e" 10 - - log_callout "[$(date)] Collecting coverage from e2e tests with proxy ..." - mkdir -p "${coverdir}/e2e_proxy" - COVERDIR="${coverdir}/e2e_proxy" run_for_module "tests" go_test "./e2e/..." "keep_going" : -tags="cov cluster_proxy" -timeout 30m "$@" || failed="$failed tests_e2e_proxy" - split_dir "${coverdir}/e2e_proxy" 10 - local cover_out_file="${coverdir}/all.coverprofile" merge_cov "${coverdir}" diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index 3b4113f342b..462bb14ec55 100644 --- a/tests/e2e/ctl_v3_completion_test.go +++ b/tests/e2e/ctl_v3_completion_test.go @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !cov - package e2e import ( diff --git a/tests/e2e/ctl_v3_watch_cov_test.go b/tests/e2e/ctl_v3_watch_cov_test.go deleted file mode 100644 index 0e17b95669e..00000000000 --- a/tests/e2e/ctl_v3_watch_cov_test.go +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2018 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. - -//go:build cov - -package e2e - -import ( - "os" - "testing" - - "go.etcd.io/etcd/tests/v3/framework/e2e" -) - -func TestCtlV3Watch(t *testing.T) { testCtl(t, watchTest) } -func TestCtlV3WatchNoTLS(t *testing.T) { testCtl(t, watchTest, withCfg(*e2e.NewConfigNoTLS())) } -func TestCtlV3WatchClientTLS(t *testing.T) { testCtl(t, watchTest, withCfg(*e2e.NewConfigClientTLS())) } -func TestCtlV3WatchPeerTLS(t *testing.T) { testCtl(t, watchTest, withCfg(*e2e.NewConfigPeerTLS())) } -func TestCtlV3WatchTimeout(t *testing.T) { testCtl(t, watchTest, withDialTimeout(0)) } - -func TestCtlV3WatchInteractive(t *testing.T) { - testCtl(t, watchTest, withInteractive()) -} -func TestCtlV3WatchInteractiveNoTLS(t *testing.T) { - testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigNoTLS())) -} -func TestCtlV3WatchInteractiveClientTLS(t *testing.T) { - testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigClientTLS())) -} -func TestCtlV3WatchInteractivePeerTLS(t *testing.T) { - testCtl(t, watchTest, withInteractive(), withCfg(*e2e.NewConfigPeerTLS())) -} - -func watchTest(cx ctlCtx) { - tests := []struct { - puts []kv - envKey string - envRange string - args []string - - wkv []kvExec - }{ - { // watch 1 key with env - puts: []kv{{"sample", "value"}}, - envKey: "sample", - args: []string{"--rev", "1"}, - wkv: []kvExec{{key: "sample", val: "value"}}, - }, - // coverage tests get extra arguments: - // ./bin/etcdctl_test -test.coverprofile=e2e.1525392462795198897.coverprofile -test.outputdir=../.. - // do not test watch exec commands - { // watch 3 keys by prefix, with env - puts: []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}, - envKey: "key", - args: []string{"--rev", "1", "--prefix"}, - wkv: []kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}, {key: "key3", val: "val3"}}, - }, - { // watch 3 keys by range, with env - puts: []kv{{"key1", "val1"}, {"key3", "val3"}, {"key2", "val2"}}, - envKey: "key", - envRange: "key3", - args: []string{"--rev", "1"}, - wkv: []kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}}, - }, - } - - for i, tt := range tests { - donec := make(chan struct{}) - go func(i int, puts []kv) { - for j := range puts { - if err := ctlV3Put(cx, puts[j].key, puts[j].val, ""); err != nil { - cx.t.Fatalf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) - } - } - close(donec) - }(i, tt.puts) - - unsetEnv := func() {} - if tt.envKey != "" || tt.envRange != "" { - if tt.envKey != "" { - os.Setenv("ETCDCTL_WATCH_KEY", tt.envKey) - unsetEnv = func() { os.Unsetenv("ETCDCTL_WATCH_KEY") } - } - if tt.envRange != "" { - os.Setenv("ETCDCTL_WATCH_RANGE_END", tt.envRange) - unsetEnv = func() { os.Unsetenv("ETCDCTL_WATCH_RANGE_END") } - } - if tt.envKey != "" && tt.envRange != "" { - unsetEnv = func() { - os.Unsetenv("ETCDCTL_WATCH_KEY") - os.Unsetenv("ETCDCTL_WATCH_RANGE_END") - } - } - } - if err := ctlV3Watch(cx, tt.args, tt.wkv...); err != nil { - if cx.dialTimeout > 0 && !isGRPCTimedout(err) { - cx.t.Errorf("watchTest #%d: ctlV3Watch error (%v)", i, err) - } - } - unsetEnv() - <-donec - } -} diff --git a/tests/e2e/ctl_v3_watch_no_cov_test.go b/tests/e2e/ctl_v3_watch_no_cov_test.go index 300a83cfa63..04ca7b6e2a8 100644 --- a/tests/e2e/ctl_v3_watch_no_cov_test.go +++ b/tests/e2e/ctl_v3_watch_no_cov_test.go @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !cov - package e2e import ( diff --git a/tests/e2e/v3_cipher_suite_test.go b/tests/e2e/v3_cipher_suite_test.go index 0b342f0f481..074dcfe5024 100644 --- a/tests/e2e/v3_cipher_suite_test.go +++ b/tests/e2e/v3_cipher_suite_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !cov && !cluster_proxy +//go:build !cluster_proxy package e2e diff --git a/tests/e2e/zap_logging_test.go b/tests/e2e/zap_logging_test.go index b416bceafe3..668311ba9bc 100644 --- a/tests/e2e/zap_logging_test.go +++ b/tests/e2e/zap_logging_test.go @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !cov - package e2e import ( diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index ff2e2f4c790..d7e6e9b5d8d 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -28,6 +28,26 @@ var ( additionalArgs func() ([]string, error) ) +const noOutputLineCount = 0 // regular binaries emit no extra lines + +func init() { + initBinPath = initBinPathNoCov + additionalArgs = additionalArgsNoCov +} + +func initBinPathNoCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + EtcdLastRelease: binDir + "/etcd-last-release", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", + } +} + +func additionalArgsNoCov() ([]string, error) { + return []string{}, nil +} + func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnNamedCmd(strings.Join(args, "_"), args, envVars) } diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go deleted file mode 100644 index 05f4c006807..00000000000 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2017 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. - -//go:build cov - -package e2e - -import ( - "fmt" - "os" - "time" - - "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/tests/v3/framework/testutils" -) - -const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines - -var ( - coverDir = testutils.MustAbsPath(os.Getenv("COVERDIR")) -) - -func init() { - initBinPath = initBinPathCov - additionalArgs = additionalArgsCov -} - -func initBinPathCov(binDir string) binPath { - return binPath{ - Etcd: binDir + "/etcd_test", - EtcdLastRelease: binDir + "/etcd-last-release", - Etcdctl: binDir + "/etcdctl_test", - Etcdutl: binDir + "/etcdutl_test", - } -} - -func additionalArgsCov() ([]string, error) { - if !fileutil.Exist(coverDir) { - return nil, fmt.Errorf("could not find coverage folder: %s", coverDir) - } - covArgs := []string{ - fmt.Sprintf("-test.coverprofile=e2e.%v.coverprofile", time.Now().UnixNano()), - "-test.outputdir=" + coverDir, - } - return covArgs, nil -} diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go deleted file mode 100644 index 62b4ff6c820..00000000000 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 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. - -//go:build !cov - -package e2e - -const noOutputLineCount = 0 // regular binaries emit no extra lines - -func init() { - initBinPath = initBinPathNoCov - additionalArgs = additionalArgsNoCov -} - -func initBinPathNoCov(binDir string) binPath { - return binPath{ - Etcd: binDir + "/etcd", - EtcdLastRelease: binDir + "/etcd-last-release", - Etcdctl: binDir + "/etcdctl", - Etcdutl: binDir + "/etcdutl", - } -} - -func additionalArgsNoCov() ([]string, error) { - return []string{}, nil -}