Use temp-directory that is covered by framework level cleanup

Prior to this PR, the e2e tests where creating dirs like:
```
/tmp/testname1.etcd030299846
/tmp/testname0.etcd039445123
/tmp/testname0.etcd206372065
```
and not cleaning them, that led to disk-space-exceeded flakes.

After the PR, the testing.TB tempdir mechanism is used and the names are
being cleaned and are more miningful:

```
../../bin/etcd --name test-TestCtlV3EndpointHashKV-2 --listen-client-urls http://localhost:20010 --advertise-client-urls http://localhost:20010 --listen-peer-urls https://localhost:20011 --initial-advertise-peer-urls https://localhost:20011 --initial-cluster-token new --data-dir /tmp/TestCtlV3EndpointHashKV429176179/003 --snapshot-count 100000 --experimental-initial-corrupt-check --peer-auto-tls --initial-cluster test-TestCtlV3EndpointHashKV-0=https://localhost:20001,test-TestCtlV3EndpointHashKV-1=https://localhost:20006,test-TestCtlV3EndpointHashKV-2=https://localhost:20011
```
This commit is contained in:
Piotr Tabor 2021-01-10 22:51:57 +01:00
parent cf2153d44b
commit f0ecad00e3
3 changed files with 13 additions and 26 deletions

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"