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

tests/etcdutil: reduce etcdutil test time #7945

Merged
merged 4 commits into from
Mar 19, 2024
Merged
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
5 changes: 4 additions & 1 deletion pkg/utils/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ type LoopWatcher struct {
// updateClientCh is used to update the etcd client.
// It's only used for testing.
updateClientCh chan *clientv3.Client
// watchChTimeoutDuration is the timeout duration for a watchChan.
watchChTimeoutDuration time.Duration
}

// NewLoopWatcher creates a new LoopWatcher.
Expand Down Expand Up @@ -448,6 +450,7 @@ func NewLoopWatcher(
loadRetryTimes: defaultLoadFromEtcdRetryTimes,
loadBatchSize: maxLoadBatchSize,
watchChangeRetryInterval: defaultEtcdRetryInterval,
watchChTimeoutDuration: WatchChTimeoutDuration,
}
}

Expand Down Expand Up @@ -597,7 +600,7 @@ func (lw *LoopWatcher) watch(ctx context.Context, revision int64) (nextRevision
cancel()
// If no message comes from an etcd watchChan for WatchChTimeoutDuration,
// create a new one and need not to reset lastReceivedResponseTime.
if time.Since(lastReceivedResponseTime) >= WatchChTimeoutDuration {
if time.Since(lastReceivedResponseTime) >= lw.watchChTimeoutDuration {
log.Warn("watch channel is blocked for a long time, recreating a new one in watch loop",
zap.Duration("timeout", time.Since(lastReceivedResponseTime)),
zap.Int64("revision", revision), zap.String("name", lw.name), zap.String("key", lw.key))
Expand Down
19 changes: 18 additions & 1 deletion pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,25 @@ func (suite *loopWatcherTestSuite) TestWatcherLoadLargeKey() {
count := 65536
ctx, cancel := context.WithCancel(suite.ctx)
defer cancel()

// create data
var wg sync.WaitGroup
tasks := make(chan int, count)
for w := 0; w < 16; w++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := range tasks {
suite.put(re, fmt.Sprintf("TestWatcherLoadLargeKey/test-%d", i), "")
}
}()
}
for i := 0; i < count; i++ {
suite.put(re, fmt.Sprintf("TestWatcherLoadLargeKey/test-%d", i), "")
tasks <- i
}
close(tasks)
wg.Wait()

cache := make([]string, 0)
watcher := NewLoopWatcher(
ctx,
Expand Down Expand Up @@ -724,6 +740,7 @@ func (suite *loopWatcherTestSuite) TestWatcherRequestProgress() {
func([]*clientv3.Event) error { return nil },
false, /* withPrefix */
)
watcher.watchChTimeoutDuration = 2 * RequestProgressInterval

suite.wg.Add(1)
go func() {
Expand Down
Loading