diff --git a/test.sh b/test.sh index 2726255ca..ee91132b6 100755 --- a/test.sh +++ b/test.sh @@ -325,14 +325,14 @@ function cov_pass { 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 + 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 + 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/etcd_spawn_cov.go b/tests/e2e/etcd_spawn_cov.go index e71c752c7..3bfd8433d 100644 --- a/tests/e2e/etcd_spawn_cov.go +++ b/tests/e2e/etcd_spawn_cov.go @@ -20,18 +20,22 @@ package e2e import ( "fmt" "os" - "path/filepath" "strings" "syscall" "time" "go.etcd.io/etcd/client/pkg/v3/fileutil" "go.etcd.io/etcd/pkg/v3/expect" + "go.etcd.io/etcd/tests/v3/integration" "go.uber.org/zap" ) const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines +var ( + coverDir = integration.MustAbsPath(os.Getenv("COVERDIR")) +) + func spawnCmd(args []string) (*expect.ExpectProcess, error) { return spawnCmdWithLogger(zap.NewNop(), args) } @@ -72,18 +76,12 @@ func spawnCmdWithLogger(lg *zap.Logger, args []string) (*expect.ExpectProcess, e } func getCovArgs() ([]string, error) { - coverPath := os.Getenv("COVERDIR") - if !filepath.IsAbs(coverPath) { - // COVERDIR is relative to etcd root but e2e test has its path set to be relative to the e2e folder. - // adding ".." in front of COVERDIR ensures that e2e saves coverage reports to the correct location. - coverPath = filepath.Join("../..", coverPath) - } - if !fileutil.Exist(coverPath) { - return nil, fmt.Errorf("could not find coverage folder") + 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=" + coverPath, + "-test.outputdir=" + coverDir, } return covArgs, nil }