mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #94537 from knight42/fix/TestCacheNoConcurrentGet
test(azure): Deflake TestCacheNoConcurrentGet
This commit is contained in:
commit
0f466ba177
@ -103,6 +103,15 @@ func (t *TimedCache) getInternal(key string) (*AzureCacheEntry, error) {
|
||||
t.Lock.Lock()
|
||||
defer t.Lock.Unlock()
|
||||
|
||||
// Another goroutine might have written the same key.
|
||||
entry, exists, err = t.Store.GetByKey(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if exists {
|
||||
return entry.(*AzureCacheEntry), nil
|
||||
}
|
||||
|
||||
// Still not found, add new entry with nil data.
|
||||
// Note the data will be filled later by getter.
|
||||
newEntry := &AzureCacheEntry{
|
||||
|
@ -195,8 +195,10 @@ func TestCacheNoConcurrentGet(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 5; i++ {
|
||||
wg.Add(1)
|
||||
go cache.Get(key, CacheReadTypeDefault)
|
||||
wg.Done()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
_, _ = cache.Get(key, CacheReadTypeDefault)
|
||||
}()
|
||||
}
|
||||
v, err := cache.Get(key, CacheReadTypeDefault)
|
||||
wg.Wait()
|
||||
|
Loading…
Reference in New Issue
Block a user