tests: Persist operation history
@@ -16,6 +16,7 @@ package linearizability
import (
"context"
+ "encoding/json"
"os"
"path/filepath"
"sort"
@@ -324,9 +325,15 @@ func checkOperationsAndPersistResults(t *testing.T, operations []porcupine.Opera
t.Error(err)
}
- linearizable, info := porcupine.CheckOperationsVerbose(model.Etcd, operations, 0)
- if linearizable != porcupine.Ok {
+ linearizable, info := porcupine.CheckOperationsVerbose(model.Etcd, operations, time.Minute)
+ if linearizable == porcupine.Illegal {
t.Error("Model is not linearizable")
+ }
+ if linearizable == porcupine.Unknown {
+ t.Error("Linearization timed out")
+ }
+ if linearizable != porcupine.Ok {
+ persistOperationHistory(t, path, operations)
persistMemberDataDir(t, clus, path)
}
@@ -338,6 +345,23 @@ func checkOperationsAndPersistResults(t *testing.T, operations []porcupine.Opera
}
}
+func persistOperationHistory(t *testing.T, path string, operations []porcupine.Operation) {
+ historyFilePath := filepath.Join(path, "history.json")
+ t.Logf("saving operation history to %q", historyFilePath)
+ file, err := os.OpenFile(historyFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
+ if err != nil {
+ t.Errorf("Failed to save operation history: %v", err)
+ return
+ }
+ encoder := json.NewEncoder(file)
+ for _, op := range operations {
+ err := encoder.Encode(op)
+ if err != nil {
+ t.Errorf("Failed to encode operation: %v", err)
+ }
+ }
+}
+
func persistMemberDataDir(t *testing.T, clus *e2e.EtcdProcessCluster, path string) {
for _, member := range clus.Procs {
memberDataDir := filepath.Join(path, member.Config().Name)
