mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
commit
2fd6787506
@ -6,7 +6,7 @@ sudo: required
|
|||||||
services: docker
|
services: docker
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.14.3
|
- 1.15.7
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
@ -30,13 +30,13 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: 1.14.3
|
- go: 1.15.7
|
||||||
env: TARGET=linux-amd64-grpcproxy
|
env: TARGET=linux-amd64-grpcproxy
|
||||||
- go: 1.14.3
|
- go: 1.15.7
|
||||||
env: TARGET=linux-amd64-coverage
|
env: TARGET=linux-amd64-coverage
|
||||||
- go: tip
|
- go: tip
|
||||||
env: TARGET=linux-amd64-fmt-unit-go-tip-2-cpu
|
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
|
env: TARGET=linux-386-unit-1-cpu
|
||||||
exclude:
|
exclude:
|
||||||
- go: tip
|
- go: tip
|
||||||
|
2
test.sh
2
test.sh
@ -67,7 +67,7 @@ fi
|
|||||||
|
|
||||||
# This options make sense for cases where SUT (System Under Test) is compiled by test.
|
# This options make sense for cases where SUT (System Under Test) is compiled by test.
|
||||||
COMMON_TEST_FLAGS=("${RACE}")
|
COMMON_TEST_FLAGS=("${RACE}")
|
||||||
if [[ ! -z "${CPU}" ]]; then
|
if [[ -n "${CPU}" ]]; then
|
||||||
COMMON_TEST_FLAGS+=("--cpu=${CPU}")
|
COMMON_TEST_FLAGS+=("--cpu=${CPU}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ package e2e
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -171,7 +170,7 @@ type etcdProcessClusterConfig struct {
|
|||||||
func newEtcdProcessCluster(t testing.TB, cfg *etcdProcessClusterConfig) (*etcdProcessCluster, error) {
|
func newEtcdProcessCluster(t testing.TB, cfg *etcdProcessClusterConfig) (*etcdProcessCluster, error) {
|
||||||
skipInShortMode(t)
|
skipInShortMode(t)
|
||||||
|
|
||||||
etcdCfgs := cfg.etcdServerProcessConfigs()
|
etcdCfgs := cfg.etcdServerProcessConfigs(t)
|
||||||
epc := &etcdProcessCluster{
|
epc := &etcdProcessCluster{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
procs: make([]etcdProcess, cfg.clusterSize),
|
procs: make([]etcdProcess, cfg.clusterSize),
|
||||||
@ -217,7 +216,7 @@ func (cfg *etcdProcessClusterConfig) peerScheme() string {
|
|||||||
return peerScheme
|
return peerScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerProcessConfig {
|
func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*etcdServerProcessConfig {
|
||||||
if cfg.basePort == 0 {
|
if cfg.basePort == 0 {
|
||||||
cfg.basePort = etcdProcessBasePort
|
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)}
|
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
|
dataDirPath := cfg.dataDirPath
|
||||||
if cfg.dataDirPath == "" {
|
if cfg.dataDirPath == "" {
|
||||||
var derr error
|
dataDirPath = tb.TempDir()
|
||||||
dataDirPath, derr = ioutil.TempDir("", name+".etcd")
|
|
||||||
if derr != nil {
|
|
||||||
panic(fmt.Sprintf("could not get tempdir for datadir: %s", derr))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
initialCluster[i] = fmt.Sprintf("%s=%s", name, purl.String())
|
initialCluster[i] = fmt.Sprintf("%s=%s", name, purl.String())
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,13 +31,6 @@ import (
|
|||||||
|
|
||||||
func TestCtlV3Snapshot(t *testing.T) { testCtl(t, snapshotTest) }
|
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) {
|
func snapshotTest(cx ctlCtx) {
|
||||||
maintenanceInitKeys(cx)
|
maintenanceInitKeys(cx)
|
||||||
|
|
||||||
@ -50,7 +42,7 @@ func snapshotTest(cx ctlCtx) {
|
|||||||
cx.t.Fatalf("snapshot: ctlV3Put error (%v)", err)
|
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)
|
defer os.RemoveAll(fpath)
|
||||||
|
|
||||||
if err = ctlV3SnapshotSave(cx, fpath); err != nil {
|
if err = ctlV3SnapshotSave(cx, fpath); err != nil {
|
||||||
@ -72,7 +64,7 @@ func snapshotTest(cx ctlCtx) {
|
|||||||
func TestCtlV3SnapshotCorrupt(t *testing.T) { testCtl(t, snapshotCorruptTest) }
|
func TestCtlV3SnapshotCorrupt(t *testing.T) { testCtl(t, snapshotCorruptTest) }
|
||||||
|
|
||||||
func snapshotCorruptTest(cx ctlCtx) {
|
func snapshotCorruptTest(cx ctlCtx) {
|
||||||
fpath := filepath.Join(tempDir(cx.t), "snapshot")
|
fpath := filepath.Join(cx.t.TempDir(), "snapshot")
|
||||||
defer os.RemoveAll(fpath)
|
defer os.RemoveAll(fpath)
|
||||||
|
|
||||||
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
|
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
|
||||||
@ -89,7 +81,7 @@ func snapshotCorruptTest(cx ctlCtx) {
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
datadir := filepath.Join(tempDir(cx.t), "data")
|
datadir := cx.t.TempDir()
|
||||||
defer os.RemoveAll(datadir)
|
defer os.RemoveAll(datadir)
|
||||||
|
|
||||||
serr := spawnWithExpect(
|
serr := spawnWithExpect(
|
||||||
@ -107,7 +99,7 @@ func snapshotCorruptTest(cx ctlCtx) {
|
|||||||
func TestCtlV3SnapshotStatusBeforeRestore(t *testing.T) { testCtl(t, snapshotStatusBeforeRestoreTest) }
|
func TestCtlV3SnapshotStatusBeforeRestore(t *testing.T) { testCtl(t, snapshotStatusBeforeRestoreTest) }
|
||||||
|
|
||||||
func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
|
func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
|
||||||
fpath := filepath.Join(tempDir(cx.t), "snapshot")
|
fpath := filepath.Join(cx.t.TempDir(), "snapshot")
|
||||||
defer os.RemoveAll(fpath)
|
defer os.RemoveAll(fpath)
|
||||||
|
|
||||||
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
|
if err := ctlV3SnapshotSave(cx, fpath); err != nil {
|
||||||
@ -120,7 +112,7 @@ func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
|
|||||||
cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err)
|
cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataDir := filepath.Join(tempDir(cx.t), "data")
|
dataDir := cx.t.TempDir()
|
||||||
defer os.RemoveAll(dataDir)
|
defer os.RemoveAll(dataDir)
|
||||||
serr := spawnWithExpect(
|
serr := spawnWithExpect(
|
||||||
append(cx.PrefixArgs(), "snapshot", "restore",
|
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)
|
defer os.RemoveAll(fpath)
|
||||||
|
|
||||||
t.Log("etcdctl saving snapshot...")
|
t.Log("etcdctl saving snapshot...")
|
||||||
@ -214,7 +206,7 @@ func TestIssue6361(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newDataDir := tempDir(t)
|
newDataDir := filepath.Join(t.TempDir(), "test.data")
|
||||||
defer os.RemoveAll(newDataDir)
|
defer os.RemoveAll(newDataDir)
|
||||||
|
|
||||||
t.Log("etcdctl restoring the snapshot...")
|
t.Log("etcdctl restoring the snapshot...")
|
||||||
@ -249,7 +241,7 @@ func TestIssue6361(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newDataDir2 := filepath.Join(tempDir(t), "newdata")
|
newDataDir2 := t.TempDir()
|
||||||
defer os.RemoveAll(newDataDir2)
|
defer os.RemoveAll(newDataDir2)
|
||||||
|
|
||||||
name2 := "infra2"
|
name2 := "infra2"
|
||||||
|
@ -65,13 +65,14 @@ func TestResumeElection(t *testing.T) {
|
|||||||
|
|
||||||
respChan := make(chan *clientv3.GetResponse)
|
respChan := make(chan *clientv3.GetResponse)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer close(respChan)
|
||||||
o := e.Observe(ctx)
|
o := e.Observe(ctx)
|
||||||
respChan <- nil
|
respChan <- nil
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case resp, ok := <-o:
|
case resp, ok := <-o:
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatal("Observe() channel closed prematurely")
|
t.Error("Observe() channel closed prematurely")
|
||||||
}
|
}
|
||||||
// Ignore any observations that candidate1 was elected
|
// Ignore any observations that candidate1 was elected
|
||||||
if string(resp.Kvs[0].Value) == "candidate1" {
|
if string(resp.Kvs[0].Value) == "candidate1" {
|
||||||
|
@ -54,7 +54,7 @@ func TestMutexLockSessionExpired(t *testing.T) {
|
|||||||
defer close(m2Locked)
|
defer close(m2Locked)
|
||||||
// m2 blocks since m1 already acquired lock /my-lock/
|
// m2 blocks since m1 already acquired lock /my-lock/
|
||||||
if err2 = m2.Lock(context.TODO()); err2 == nil {
|
if err2 = m2.Lock(context.TODO()); err2 == nil {
|
||||||
t.Fatal("expect session expired error")
|
t.Error("expect session expired error")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user