mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Refactor reporting results
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
d99b1dbdaf
commit
0cd5c9ca37
@ -175,51 +175,63 @@ func TestLinearizability(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testLinearizability(ctx context.Context, t *testing.T, lg *zap.Logger, config e2e.EtcdProcessClusterConfig, traffic *trafficConfig, failpoint FailpointConfig) {
|
func testLinearizability(ctx context.Context, t *testing.T, lg *zap.Logger, config e2e.EtcdProcessClusterConfig, traffic *trafficConfig, failpoint FailpointConfig) {
|
||||||
var responses [][]watchResponse
|
r := report{lg: lg}
|
||||||
var events [][]watchEvent
|
var err error
|
||||||
var operations []porcupine.Operation
|
r.clus, err = e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&config))
|
||||||
var patchedOperations []porcupine.Operation
|
|
||||||
var visualizeHistory func(path string)
|
|
||||||
|
|
||||||
clus, err := e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&config))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer clus.Close()
|
defer r.clus.Close()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
r.Report(t)
|
||||||
|
}()
|
||||||
|
r.operations, r.responses = runScenario(ctx, t, lg, r.clus, *traffic, failpoint)
|
||||||
|
forcestopCluster(r.clus)
|
||||||
|
|
||||||
|
watchProgressNotifyEnabled := r.clus.Cfg.WatchProcessNotifyInterval != 0
|
||||||
|
validateWatchResponses(t, r.responses, watchProgressNotifyEnabled)
|
||||||
|
|
||||||
|
r.events = watchEvents(r.responses)
|
||||||
|
validateEventsMatch(t, r.events)
|
||||||
|
|
||||||
|
r.patchedOperations = patchOperationBasedOnWatchEvents(r.operations, longestHistory(r.events))
|
||||||
|
r.visualizeHistory = validateOperationHistoryAndReturnVisualize(t, lg, r.patchedOperations)
|
||||||
|
}
|
||||||
|
|
||||||
|
type report struct {
|
||||||
|
lg *zap.Logger
|
||||||
|
clus *e2e.EtcdProcessCluster
|
||||||
|
responses [][]watchResponse
|
||||||
|
events [][]watchEvent
|
||||||
|
operations []porcupine.Operation
|
||||||
|
patchedOperations []porcupine.Operation
|
||||||
|
visualizeHistory func(path string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *report) Report(t *testing.T) {
|
||||||
path := testResultsDirectory(t)
|
path := testResultsDirectory(t)
|
||||||
if t.Failed() {
|
if t.Failed() {
|
||||||
for i, member := range clus.Procs {
|
for i, member := range r.clus.Procs {
|
||||||
memberDataDir := filepath.Join(path, member.Config().Name)
|
memberDataDir := filepath.Join(path, member.Config().Name)
|
||||||
persistMemberDataDir(t, lg, member, memberDataDir)
|
persistMemberDataDir(t, r.lg, member, memberDataDir)
|
||||||
if responses != nil {
|
if r.responses != nil {
|
||||||
persistWatchResponses(t, lg, filepath.Join(memberDataDir, "responses.json"), responses[i])
|
persistWatchResponses(t, r.lg, filepath.Join(memberDataDir, "responses.json"), r.responses[i])
|
||||||
}
|
}
|
||||||
if events != nil {
|
if r.events != nil {
|
||||||
persistWatchEvents(t, lg, filepath.Join(memberDataDir, "events.json"), events[i])
|
persistWatchEvents(t, r.lg, filepath.Join(memberDataDir, "events.json"), r.events[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if operations != nil {
|
if r.operations != nil {
|
||||||
persistOperationHistory(t, lg, filepath.Join(path, "full-history.json"), operations)
|
persistOperationHistory(t, r.lg, filepath.Join(path, "full-history.json"), r.operations)
|
||||||
}
|
}
|
||||||
if patchedOperations != nil {
|
if r.patchedOperations != nil {
|
||||||
persistOperationHistory(t, lg, filepath.Join(path, "patched-history.json"), patchedOperations)
|
persistOperationHistory(t, r.lg, filepath.Join(path, "patched-history.json"), r.patchedOperations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visualizeHistory(filepath.Join(path, "history.html"))
|
if r.visualizeHistory != nil {
|
||||||
}()
|
r.visualizeHistory(filepath.Join(path, "history.html"))
|
||||||
operations, responses = runScenario(ctx, t, lg, clus, *traffic, failpoint)
|
}
|
||||||
forcestopCluster(clus)
|
|
||||||
|
|
||||||
watchProgressNotifyEnabled := clus.Cfg.WatchProcessNotifyInterval != 0
|
|
||||||
validateWatchResponses(t, responses, watchProgressNotifyEnabled)
|
|
||||||
|
|
||||||
events = watchEvents(responses)
|
|
||||||
validateEventsMatch(t, events)
|
|
||||||
|
|
||||||
patchedOperations = patchOperationBasedOnWatchEvents(operations, longestHistory(events))
|
|
||||||
visualizeHistory = validateOperationHistoryAndReturnVisualize(t, lg, patchedOperations)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runScenario(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, traffic trafficConfig, failpoint FailpointConfig) (operations []porcupine.Operation, responses [][]watchResponse) {
|
func runScenario(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, traffic trafficConfig, failpoint FailpointConfig) (operations []porcupine.Operation, responses [][]watchResponse) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user