Repository: etcd-io/etcd
File: tests/robustness/traffic/traffic.go (Go)

Code before:
func (p Profile) WithBackgroundWatchConfigRevisionOffset(offset int64) Profile {
	p.BackgroundWatchConfig.RevisionOffset = offset
	return p
}

type RunTrafficLoopParam struct {
	Client                             *client.RecordingClient
	QPSLimiter                         *rate.Limiter
	IDs                                identity.Provider
	LeaseIDStorage                     identity.LeaseIDStorage
	NonUniqueRequestConcurrencyLimiter ConcurrencyLimiter
	KeyStore                           *keyStore
	Finish                             <-chan struct{}
}

type RunCompactLoopParam struct {
	Client *client.RecordingClient
	Period time.Duration
	Finish <-chan struct{}
}

type RunWatchLoopParam struct {
	Client                        *client.RecordingClient
	KeyStore                      *keyStore
	Finish                        <-chan struct{}
	options.BackgroundWatchConfig // Embedded: Interval and RevisionOffset
}

const (
	DefaultWatchInterval  = 100 * time.Millisecond
	DefaultRevisionOffset = 100
)

type Traffic interface {
	RunKeyValueLoop(ctx context.Context, param RunTrafficLoopParam)
	RunWatchLoop(ctx context.Context, param RunWatchLoopParam)
	RunCompactLoop(ctx context.Context, param RunCompactLoopParam)
	ExpectUniqueRevision() bool
}

// runWatchLoop is a helper function that implements the periodic watch loop pattern.
// It spawns watches at regular intervals with random revision offsets.
func runWatchLoop(ctx context.Context, p RunWatchLoopParam, cfg watchLoopConfig) {
	for {
		select {
		case <-ctx.Done():
			return
		case <-p.Finish:
			return
		case <-time.After(p.BackgroundWatchConfig.Interval):
			// Time to spawn a new watch

Review comment (suggestion):
```suggestion
	Watch options.BackgroundWatchConfig
```

It's no longer a "background" watch.

Code after:

func (p Profile) WithoutCompaction() Profile {
	p.ForbidCompaction = true
	return p
}

func (p Profile) WithCompactionPeriod(cp time.Duration) Profile {
	p.CompactPeriod = cp
	return p
}

func (p Profile) WithWatchInterval(interval time.Duration) Profile {
	p.Interval = interval
	return p
}

func (p Profile) WithWatchRevisionOffset(offset int64) Profile {
	p.RevisionOffset = offset
	return p
}

type RunTrafficLoopParam struct {
	Client                             *client.RecordingClient
	QPSLimiter                         *rate.Limiter
	IDs                                identity.Provider
	LeaseIDStorage                     identity.LeaseIDStorage
	NonUniqueRequestConcurrencyLimiter ConcurrencyLimiter
	KeyStore                           *keyStore
	Finish                             <-chan struct{}
}

type RunCompactLoopParam struct {
	Client *client.RecordingClient
	Period time.Duration
	Finish <-chan struct{}
}

type RunWatchLoopParam struct {
	Client              *client.RecordingClient
	KeyStore            *keyStore
	Finish              <-chan struct{}
	options.WatchConfig // Embedded: Interval and RevisionOffset
}

type Traffic interface {
	RunKeyValueLoop(ctx context.Context, param RunTrafficLoopParam)
	RunWatchLoop(ctx context.Context, param RunWatchLoopParam)
	RunCompactLoop(ctx context.Context, param RunCompactLoopParam)
	ExpectUniqueRevision() bool
}