Skip to content

Commit

Permalink
Merge pull request etcd-io#18930 from serathius/robustness-jitter
Browse files Browse the repository at this point in the history
Add jitter to failpoint injection to cover periodily executed compaction
  • Loading branch information
serathius authored Nov 20, 2024
2 parents ce13079 + d961c81 commit 14f4df4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 12 additions & 2 deletions tests/robustness/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import (

var testRunner = framework.E2eTestRunner

var (
WaitBeforeFailpoint = time.Second
WaitJitter = traffic.CompactionPeriod
WaitAfterFailpoint = time.Second
)

func TestMain(m *testing.M) {
rand.Seed(time.Now().UnixNano())
testRunner.TestMain(m)
Expand Down Expand Up @@ -116,14 +122,14 @@ func runScenario(ctx context.Context, t *testing.T, s scenarios.TestScenario, lg
g.Go(func() error {
defer close(failpointInjected)
// Give some time for traffic to reach qps target before injecting failpoint.
time.Sleep(time.Second)
time.Sleep(randomizeTime(WaitBeforeFailpoint, WaitJitter))
fr, err := failpoint.Inject(ctx, t, lg, clus, s.Failpoint, baseTime, ids)
if err != nil {
t.Error(err)
cancel()
}
// Give some time for traffic to reach qps target after injecting failpoint.
time.Sleep(time.Second)
time.Sleep(randomizeTime(WaitAfterFailpoint, WaitJitter))
if fr != nil {
failpointInjected <- fr.FailpointInjection
failpointClientReport = fr.Client
Expand All @@ -147,6 +153,10 @@ func runScenario(ctx context.Context, t *testing.T, s scenarios.TestScenario, lg
return append(operationReport, append(failpointClientReport, watchReport...)...)
}

func randomizeTime(base time.Duration, jitter time.Duration) time.Duration {
return base - jitter + time.Duration(rand.Int63n(int64(jitter)*2))
}

func operationsMaxRevision(reports []report.ClientReport) int64 {
var maxRevision int64
for _, r := range reports {
Expand Down
6 changes: 2 additions & 4 deletions tests/robustness/traffic/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ var (
RequestTimeout = 200 * time.Millisecond
WatchTimeout = time.Second
MultiOpTxnOpCount = 4
CompactionPeriod = 200 * time.Millisecond

LowTraffic = Profile{
MinimalQPS: 100,
MaximalQPS: 200,
ClientCount: 8,
MaxNonUniqueRequestConcurrency: 3,
CompactPeriod: 200 * time.Millisecond,
}
HighTrafficProfile = Profile{
MinimalQPS: 200,
MaximalQPS: 1000,
ClientCount: 8,
MaxNonUniqueRequestConcurrency: 3,
CompactPeriod: 200 * time.Millisecond,
}
)

Expand Down Expand Up @@ -97,7 +96,7 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
defer wg.Done()
defer c.Close()

RunCompactLoop(ctx, c, profile.CompactPeriod, finish)
RunCompactLoop(ctx, c, CompactionPeriod, finish)
mux.Lock()
reports = append(reports, c.Report())
mux.Unlock()
Expand Down Expand Up @@ -177,7 +176,6 @@ type Profile struct {
MaxNonUniqueRequestConcurrency int
ClientCount int
ForbidCompaction bool
CompactPeriod time.Duration
}

func (p Profile) WithoutCompaction() Profile {
Expand Down

0 comments on commit 14f4df4

Please sign in to comment.