Merge pull request #12653 from etcd-io/20201111-fix-flakes-go15

Tests:Use temp-directory that is covered by framework level cleanup
This commit is contained in:
Piotr Tabor 2021-01-31 11:05:13 +01:00 committed by GitHub
commit 2fd6787506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 32 deletions

View File

@ -6,7 +6,7 @@ sudo: required
services: docker
go:
- 1.14.3
- 1.15.7
- tip
notifications:
@ -30,13 +30,13 @@ env:
matrix:
fast_finish: true
allow_failures:
- go: 1.14.3
- go: 1.15.7
env: TARGET=linux-amd64-grpcproxy
- go: 1.14.3
- go: 1.15.7
env: TARGET=linux-amd64-coverage
- go: tip
env: TARGET=linux-amd64-fmt-unit-go-tip-2-cpu
- go: 1.14.3
- go: 1.15.7
env: TARGET=linux-386-unit-1-cpu
exclude:
- go: tip

View File

@ -67,7 +67,7 @@ fi
# This options make sense for cases where SUT (System Under Test) is compiled by test.
COMMON_TEST_FLAGS=("${RACE}")
if [[ ! -z "${CPU}" ]]; then
if [[ -n "${CPU}" ]]; then
COMMON_TEST_FLAGS+=("--cpu=${CPU}")
fi

View File

@ -16,7 +16,6 @@ package e2e
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"strings"
@ -171,7 +170,7 @@ type etcdProcessClusterConfig struct {
func newEtcdProcessCluster(t testing.TB, cfg *etcdProcessClusterConfig) (*etcdProcessCluster, error) {
skipInShortMode(t)
etcdCfgs := cfg.etcdServerProcessConfigs()
etcdCfgs := cfg.etcdServerProcessConfigs(t)
epc := &etcdProcessCluster{
cfg: cfg,
procs: make([]etcdProcess, cfg.clusterSize),
@ -217,7 +216,7 @@ func (cfg *etcdProcessClusterConfig) peerScheme() string {
return peerScheme
}
func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerProcessConfig {
func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*etcdServerProcessConfig {
if cfg.basePort == 0 {
cfg.basePort = etcdProcessBasePort
}
@ -247,14 +246,10 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro
}
purl := url.URL{Scheme: cfg.peerScheme(), Host: fmt.Sprintf("localhost:%d", port+1)}
name := fmt.Sprintf("testname%d", i)
name := fmt.Sprintf("test-%s-%d", tb.Name(), i)
dataDirPath := cfg.dataDirPath
if cfg.dataDirPath == "" {
var derr error
dataDirPath, derr = ioutil.TempDir("", name+".etcd")
if derr != nil {
panic(fmt.Sprintf("could not get tempdir for datadir: %s", derr))
}
dataDirPath = tb.TempDir()
}
initialCluster[i] = fmt.Sprintf("%s=%s", name, purl.String())

View File

@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"os"
"path/filepath"
"strings"
@ -32,13 +31,6 @@ import (
func TestCtlV3Snapshot(t *testing.T) { testCtl(t, snapshotTest) }
// TODO: Replace with testing.T.TestDir() in golang-1.15.
func tempDir(tb testing.TB) string {
dir := filepath.Join(os.TempDir(), tb.Name(), fmt.Sprint(rand.Int()))
os.MkdirAll(dir, 0700)
return dir
}
func snapshotTest(cx ctlCtx) {
maintenanceInitKeys(cx)
@ -50,7 +42,7 @@ func snapshotTest(cx ctlCtx) {
cx.t.Fatalf("snapshot: ctlV3Put error (%v)", err)
}
fpath := filepath.Join(tempDir(cx.t), "snapshot")
fpath := filepath.Join(cx.t.TempDir(), "snapshot")
defer os.RemoveAll(fpath)
if err = ctlV3SnapshotSave(cx, fpath); err != nil {
@ -72,7 +64,7 @@ func snapshotTest(cx ctlCtx) {
func TestCtlV3SnapshotCorrupt(t *testing.T) { testCtl(t, snapshotCorruptTest) }
func snapshotCorruptTest(cx ctlCtx) {
fpath := filepath.Join(tempDir(cx.t), "snapshot")
fpath := filepath.Join(cx.t.TempDir(), "snapshot")
defer os.RemoveAll(fpath)
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
@ -89,7 +81,7 @@ func snapshotCorruptTest(cx ctlCtx) {
}
f.Close()
datadir := filepath.Join(tempDir(cx.t), "data")
datadir := cx.t.TempDir()
defer os.RemoveAll(datadir)
serr := spawnWithExpect(
@ -107,7 +99,7 @@ func snapshotCorruptTest(cx ctlCtx) {
func TestCtlV3SnapshotStatusBeforeRestore(t *testing.T) { testCtl(t, snapshotStatusBeforeRestoreTest) }
func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
fpath := filepath.Join(tempDir(cx.t), "snapshot")
fpath := filepath.Join(cx.t.TempDir(), "snapshot")
defer os.RemoveAll(fpath)
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
@ -120,7 +112,7 @@ func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err)
}
dataDir := filepath.Join(tempDir(cx.t), "data")
dataDir := cx.t.TempDir()
defer os.RemoveAll(dataDir)
serr := spawnWithExpect(
append(cx.PrefixArgs(), "snapshot", "restore",
@ -201,7 +193,7 @@ func TestIssue6361(t *testing.T) {
}
}
fpath := filepath.Join(tempDir(t), "snapshot")
fpath := filepath.Join(t.TempDir(), "test.snapshot")
defer os.RemoveAll(fpath)
t.Log("etcdctl saving snapshot...")
@ -214,7 +206,7 @@ func TestIssue6361(t *testing.T) {
t.Fatal(err)
}
newDataDir := tempDir(t)
newDataDir := filepath.Join(t.TempDir(), "test.data")
defer os.RemoveAll(newDataDir)
t.Log("etcdctl restoring the snapshot...")
@ -249,7 +241,7 @@ func TestIssue6361(t *testing.T) {
t.Fatal(err)
}
newDataDir2 := filepath.Join(tempDir(t), "newdata")
newDataDir2 := t.TempDir()
defer os.RemoveAll(newDataDir2)
name2 := "infra2"

View File

@ -65,13 +65,14 @@ func TestResumeElection(t *testing.T) {
respChan := make(chan *clientv3.GetResponse)
go func() {
defer close(respChan)
o := e.Observe(ctx)
respChan <- nil
for {
select {
case resp, ok := <-o:
if !ok {
t.Fatal("Observe() channel closed prematurely")
t.Error("Observe() channel closed prematurely")
}
// Ignore any observations that candidate1 was elected
if string(resp.Kvs[0].Value) == "candidate1" {

View File

@ -54,7 +54,7 @@ func TestMutexLockSessionExpired(t *testing.T) {
defer close(m2Locked)
// m2 blocks since m1 already acquired lock /my-lock/
if err2 = m2.Lock(context.TODO()); err2 == nil {
t.Fatal("expect session expired error")
t.Error("expect session expired error")
}
}()