mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Preserve data dir from failed linearizability tests
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
f482f7b4a4
commit
04caec5960
@ -17,6 +17,7 @@ package linearizability
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -104,22 +105,11 @@ func testLinearizability(ctx context.Context, t *testing.T, config e2e.EtcdProce
|
||||
}
|
||||
}()
|
||||
operations := simulateTraffic(ctx, t, clus, traffic)
|
||||
clus.Close()
|
||||
|
||||
linearizable, info := porcupine.CheckOperationsVerbose(etcdModel, operations, 0)
|
||||
if linearizable != porcupine.Ok {
|
||||
t.Error("Model is not linearizable")
|
||||
}
|
||||
|
||||
path, err := filepath.Abs(filepath.Join(resultsDirectory, strings.Replace(t.Name(), "/", "_", -1)+".html"))
|
||||
err = clus.Stop()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = porcupine.VisualizePath(etcdModel, info, path)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to visualize, err: %v", err)
|
||||
}
|
||||
t.Logf("saving visualization to %q", path)
|
||||
checkOperationsAndPersistResults(t, operations, clus)
|
||||
}
|
||||
|
||||
func triggerFailpoints(ctx context.Context, t *testing.T, clus *e2e.EtcdProcessCluster, config FailpointConfig) error {
|
||||
@ -192,3 +182,50 @@ type trafficConfig struct {
|
||||
clientCount int
|
||||
traffic Traffic
|
||||
}
|
||||
|
||||
func checkOperationsAndPersistResults(t *testing.T, operations []porcupine.Operation, clus *e2e.EtcdProcessCluster) {
|
||||
path, err := testResultsDirectory(t)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
linearizable, info := porcupine.CheckOperationsVerbose(etcdModel, operations, 0)
|
||||
if linearizable != porcupine.Ok {
|
||||
t.Error("Model is not linearizable")
|
||||
persistMemberDataDir(t, clus, path)
|
||||
}
|
||||
|
||||
visualizationPath := filepath.Join(path, "history.html")
|
||||
t.Logf("saving visualization to %q", visualizationPath)
|
||||
err = porcupine.VisualizePath(etcdModel, info, visualizationPath)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to visualize, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func persistMemberDataDir(t *testing.T, clus *e2e.EtcdProcessCluster, path string) {
|
||||
for _, member := range clus.Procs {
|
||||
memberDataDir := filepath.Join(path, member.Config().Name)
|
||||
err := os.RemoveAll(memberDataDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Logf("saving %s data dir to %q", member.Config().Name, memberDataDir)
|
||||
err = os.Rename(member.Config().DataDirPath, memberDataDir)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testResultsDirectory(t *testing.T) (string, error) {
|
||||
path, err := filepath.Abs(filepath.Join(resultsDirectory, strings.Replace(t.Name(), "/", "_", -1)))
|
||||
if err != nil {
|
||||
return path, err
|
||||
}
|
||||
err = os.MkdirAll(path, 0700)
|
||||
if err != nil {
|
||||
return path, err
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user