Skip to content
Draft
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
4 changes: 4 additions & 0 deletions tests/robustness/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ func (c *RecordingClient) Endpoints() []string {
return c.client.Endpoints()
}

func (c *RecordingClient) SetEndpoints(endpoints ...string) {
c.client.SetEndpoints(endpoints...)
}

func (c *RecordingClient) Watch(ctx context.Context, key string, rev int64, withPrefix bool, withProgressNotify bool, withPrevKV bool) clientv3.WatchChan {
request := model.WatchRequest{
Key: key,
Expand Down
43 changes: 40 additions & 3 deletions tests/robustness/traffic/traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package traffic

import (
"context"
"math/rand"
"slices"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -139,6 +141,14 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
defer wg.Done()
defer c.Close()

if profile.Watch != nil && profile.Watch.EndpointSwitchPeriod != nil {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is a better idea than treating 0 as "don't switch".

wg.Add(1)
go func() {
defer wg.Done()
runEndpointSwitchLoop(ctx, c, endpoints, *profile.Watch.EndpointSwitchPeriod, finish)
}()
}

traffic.RunKeyValueLoop(ctx, RunTrafficLoopParam{
Client: c,
QPSLimiter: limiter,
Expand Down Expand Up @@ -177,6 +187,15 @@ func SimulateTraffic(ctx context.Context, t *testing.T, lg *zap.Logger, clus *e2
go func(c *client.RecordingClient) {
defer wg.Done()
defer c.Close()

if profile.Watch != nil && profile.Watch.EndpointSwitchPeriod != nil {
wg.Add(1)
go func() {
defer wg.Done()
runEndpointSwitchLoop(ctx, c, endpoints, *profile.Watch.EndpointSwitchPeriod, finish)
}()
}

traffic.RunWatchLoop(ctx, RunWatchLoopParam{
Config: *profile.Watch,
Client: c,
Expand Down Expand Up @@ -375,9 +394,10 @@ type KeyValue struct {
}

type Watch struct {
MemberClientCount int
ClusterClientCount int
RevisionOffsetRange Range
MemberClientCount int
ClusterClientCount int
RevisionOffsetRange Range
EndpointSwitchPeriod *time.Duration
}

type Compaction struct {
Expand Down Expand Up @@ -495,3 +515,20 @@ func CheckEmptyDatabaseAtStart(ctx context.Context, lg *zap.Logger, endpoints []
}
return nil
}

func runEndpointSwitchLoop(ctx context.Context, c *client.RecordingClient, endpoints []string, period time.Duration, finish <-chan struct{}) {
for {
select {
case <-ctx.Done():
return
case <-finish:
return
case <-time.After(period):
shuffledEndpoints := slices.Clone(endpoints)
rand.Shuffle(len(shuffledEndpoints), func(i, j int) {
shuffledEndpoints[i], shuffledEndpoints[j] = shuffledEndpoints[j], shuffledEndpoints[i]
})
c.SetEndpoints(shuffledEndpoints...)
}
}
}