Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

robustness: make qps below threshold retriable test. #17725

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions tests/robustness/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
"go.etcd.io/etcd/tests/v3/robustness/validate"
)

const (
robustnessRetries = 3
)

var testRunner = framework.E2eTestRunner

func TestMain(m *testing.M) {
Expand All @@ -46,7 +50,7 @@ func TestRobustnessExploratory(t *testing.T) {
lg := zaptest.NewLogger(t)
scenario.cluster.Logger = lg
ctx := context.Background()
testRobustness(ctx, t, lg, scenario)
testRobustnessWithRetry(ctx, t, lg, scenario)
})
}
}
Expand All @@ -58,12 +62,36 @@ func TestRobustnessRegression(t *testing.T) {
lg := zaptest.NewLogger(t)
scenario.cluster.Logger = lg
ctx := context.Background()
testRobustness(ctx, t, lg, scenario)
testRobustnessWithRetry(ctx, t, lg, scenario)
})
}
}

func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testScenario) {
func testRobustnessWithRetry(ctx context.Context, t *testing.T, lg *zap.Logger, s testScenario) {
var err error
retryAttemps := 0
for retryAttemps < robustnessRetries {
select {
case <-ctx.Done():
return
default:
}
retryAttemps++
err = testRobustness(ctx, t, lg, &s)
if err == nil {
break
}
t.Logf("retrying robustness test with error: %v", err)
}
t.Logf("retried %s %d times", s.name, retryAttemps)
if err != nil {
t.Error(err)
}
}

// testRobustness runs one robustness test, and returns a retriable error.
// Retriable errors include qps < minimal qps which can be temporary.
func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s *testScenario) (retriableErr error) {
report := report.TestReport{Logger: lg}
var err error
report.Cluster, err = e2e.NewEtcdProcessCluster(ctx, t, e2e.WithConfig(&s.cluster))
Expand All @@ -88,7 +116,7 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce
defer func() {
report.Report(t, panicked)
}()
report.Client = s.run(ctx, t, lg, report.Cluster)
report.Client, retriableErr = s.run(ctx, t, lg, report.Cluster)
forcestopCluster(report.Cluster)

watchProgressNotifyEnabled := report.Cluster.Cfg.ServerConfig.ExperimentalWatchProgressNotifyInterval != 0
Expand All @@ -97,9 +125,10 @@ func testRobustness(ctx context.Context, t *testing.T, lg *zap.Logger, s testSce
report.Visualize = validate.ValidateAndReturnVisualize(t, lg, validateConfig, report.Client)

panicked = false
return retriableErr
}

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, retriableErr error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
g := errgroup.Group{}
Expand All @@ -114,8 +143,8 @@ func (s testScenario) run(ctx context.Context, t *testing.T, lg *zap.Logger, clu
defer close(finishTraffic)
err := failpoint.Inject(ctx, t, lg, clus, s.failpoint)
if err != nil {
t.Error(err)
cancel()
t.Fatal(err)
Comment on lines -117 to +147
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to understand this better, if we use t.Fatal here, we won't end up retrying the test right?
Referring to the comment here: #17725 (comment)

}
time.Sleep(time.Second)
lg.Info("Finished injecting failures")
Expand All @@ -124,7 +153,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, retriableErr = traffic.SimulateTraffic(ctx, t, lg, clus, s.profile, s.traffic, finishTraffic, baseTime, ids)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think considering that this is the only place we are setting retriableErr, this should be fine, but in the future if we set it in any of the other goroutines, that might be a race.

How about returning the err instead of nil in this goroutine and catching it as part of g.Wait() below?

maxRevision := operationsMaxRevision(operationReport)
maxRevisionChan <- maxRevision
lg.Info("Finished simulating traffic", zap.Int64("max-revision", maxRevision))
Expand All @@ -135,7 +164,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...), retriableErr
}

func operationsMaxRevision(reports []report.ClientReport) int64 {
Expand Down
12 changes: 7 additions & 5 deletions tests/robustness/traffic/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package traffic

import (
"context"
"fmt"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -50,7 +51,7 @@ 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, error) {
mux := sync.Mutex{}
endpoints := clus.EndpointsGRPC()

Expand Down Expand Up @@ -85,11 +86,11 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
wg.Wait()
endTime := time.Now()

// Ensure that last operation is succeeds
// Ensure that last operation succeeds
time.Sleep(time.Second)
_, err = cc.Put(ctx, "tombstone", "true")
if err != nil {
t.Error(err)
t.Fatal(err)
}
reports = append(reports, cc.Report())

Expand All @@ -102,9 +103,10 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
qps := float64(operationCount) / float64(endTime.Sub(startTime)) * float64(time.Second)
lg.Info("Average traffic", zap.Float64("qps", qps))
if qps < profile.MinimalQPS {
t.Errorf("Requiring minimal %f qps for test results to be reliable, got %f qps", profile.MinimalQPS, qps)
// returns a retriable error
return reports, fmt.Errorf("requiring minimal %f qps for test results to be reliable, got %f qps", profile.MinimalQPS, qps)
}
return reports
return reports, nil
}

type Profile struct {
Expand Down
Loading