Skip to content

Commit

Permalink
robustness: skip saving the report if test failed due to qps.
Browse files Browse the repository at this point in the history
Signed-off-by: Siyuan Zhang <[email protected]>
  • Loading branch information
siyuanfoundation committed Apr 19, 2024
1 parent 64b338a commit 531f5cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
12 changes: 7 additions & 5 deletions tests/robustness/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce
// save data on panicking.
// Refer to: https://github.com/golang/go/issues/49929
panicked := true
passQPSRequirements := true
defer func() {
r.Report(t, panicked)
r.Report(t, panicked, passQPSRequirements)
}()
r.Client = s.run(ctx, t, lg, r.Cluster)
r.Client, passQPSRequirements = s.run(ctx, t, lg, r.Cluster)
persistedRequests, err := report.PersistedRequestsCluster(lg, r.Cluster)
if err != nil {
t.Fatal(err)
Expand All @@ -105,11 +106,12 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce
panicked = false
}

func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster) (reports []report.ClientReport) {
func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster) (reports []report.ClientReport, passQPSRequirements bool) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
g := errgroup.Group{}
var operationReport, watchReport []report.ClientReport
passQPSRequirements = true
finishTraffic := make(chan struct{})

// using baseTime time-measuring operation to get monotonic clock reading
Expand All @@ -130,7 +132,7 @@ func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clu
maxRevisionChan := make(chan int64, 1)
g.Go(func() error {
defer close(maxRevisionChan)
operationReport = traffic.SimulateTraffic(ctx, t, lg, clus, s.profile, s.traffic, finishTraffic, baseTime, ids)
operationReport, passQPSRequirements = traffic.SimulateTraffic(ctx, t, lg, clus, s.profile, s.traffic, finishTraffic, baseTime, ids)
maxRevision := operationsMaxRevision(operationReport)
maxRevisionChan <- maxRevision
lg.Info("Finished simulating traffic", zap.Int64("max-revision", maxRevision))
Expand All @@ -141,7 +143,7 @@ func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clu
return nil
})
g.Wait()
return append(operationReport, watchReport...)
return append(operationReport, watchReport...), passQPSRequirements
}

func operationsMaxRevision(reports []report.ClientReport) int64 {
Expand Down
5 changes: 3 additions & 2 deletions tests/robustness/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ func testResultsDirectory(t *testing.T) string {
return path
}

func (r *TestReport) Report(t *testing.T, force bool) {
func (r *TestReport) Report(t *testing.T, force, passQPSRequirements bool) {
_, persistResultsEnvSet := os.LookupEnv("PERSIST_RESULTS")
if !t.Failed() && !force && !persistResultsEnvSet {
// not saving the report if the test succeeds, or if it failed due to QPSRequirements
if (!t.Failed() || !passQPSRequirements) && !force && !persistResultsEnvSet {
return
}
path := testResultsDirectory(t)
Expand Down
6 changes: 4 additions & 2 deletions tests/robustness/traffic/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ var (
}
)

func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, profile Profile, traffic Traffic, finish <-chan struct{}, baseTime time.Time, ids identity.Provider) []report.ClientReport {
func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2e.EtcdProcessCluster, profile Profile, traffic Traffic, finish <-chan struct{}, baseTime time.Time, ids identity.Provider) ([]report.ClientReport, bool) {
passQPSRequirements := true
mux := sync.Mutex{}
endpoints := clus.EndpointsGRPC()

Expand Down Expand Up @@ -110,9 +111,10 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
qps := float64(successfulOperations) / period.Seconds()
lg.Info("Traffic from successful requests", zap.Float64("qps", qps), zap.Int("operations", successfulOperations), zap.Duration("period", period))
if qps < profile.MinimalQPS {
passQPSRequirements = false
t.Errorf("Requiring minimal %f qps for test results to be reliable, got %f qps", profile.MinimalQPS, qps)
}
return reports
return reports, passQPSRequirements
}

type Profile struct {
Expand Down

0 comments on commit 531f5cc

Please sign in to comment.