Skip to content

Commit

Permalink
Merge pull request #14714 from serathius/linearizability-data-dir
Browse files Browse the repository at this point in the history
tests: Preserve data dir from failed linearizability tests
  • Loading branch information
serathius authored Nov 10, 2022
2 parents 0bff3ad + 04caec5 commit 2f558ca
Showing 1 changed file with 50 additions and 13 deletions.
63 changes: 50 additions & 13 deletions tests/linearizability/linearizability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package linearizability
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 2f558ca

Please sign in to comment.