mirror of
https://github.com/etcd-io/etcd.git
synced 2026-02-05 06:46:49 +01:00
cache: deflake TestCacheCompactionResync
The test had a race condition where Phase 3 checked lastStartRev before the cache finished updating it. The mw.registered channel was already closed from Phase 1, so <-mw.registered returned immediately instead of waiting. Fix: Add resetRegistered() to create a fresh channel for Phase 3, ensuring the test properly waits for the cache to complete recovery. Fixes #21150 Signed-off-by: HossamSaberX <hossam.sabeer55@gmail.com>
This commit is contained in:
10
cache/cache_test.go
vendored
10
cache/cache_test.go
vendored
@@ -455,7 +455,9 @@ func TestCacheCompactionResync(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Log("Phase 3: resync after compaction")
|
||||
mw.resetRegistered()
|
||||
mw.triggerCreatedNotify()
|
||||
<-mw.registered
|
||||
expectSnapshotRev := int64(20)
|
||||
ctxResync, cancelResync := context.WithTimeout(t.Context(), time.Second)
|
||||
defer cancelResync()
|
||||
@@ -558,6 +560,8 @@ func (m *mockWatcher) getLastStartRev() int64 {
|
||||
}
|
||||
|
||||
func (m *mockWatcher) signalRegistration() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
select {
|
||||
case <-m.registered:
|
||||
default:
|
||||
@@ -565,6 +569,12 @@ func (m *mockWatcher) signalRegistration() {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockWatcher) resetRegistered() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.registered = make(chan struct{})
|
||||
}
|
||||
|
||||
func (m *mockWatcher) streamResponses(ctx context.Context, out chan<- clientv3.WatchResponse) {
|
||||
defer func() {
|
||||
close(out)
|
||||
|
||||
Reference in New Issue
Block a user