mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +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()
|
t.Lock.Lock()
|
||||||
defer t.Lock.Unlock()
|
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.
|
// Still not found, add new entry with nil data.
|
||||||
// Note the data will be filled later by getter.
|
// Note the data will be filled later by getter.
|
||||||
newEntry := &AzureCacheEntry{
|
newEntry := &AzureCacheEntry{
|
||||||
|
@ -195,8 +195,10 @@ func TestCacheNoConcurrentGet(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go cache.Get(key, CacheReadTypeDefault)
|
go func() {
|
||||||
wg.Done()
|
defer wg.Done()
|
||||||
|
_, _ = cache.Get(key, CacheReadTypeDefault)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
v, err := cache.Get(key, CacheReadTypeDefault)
|
v, err := cache.Get(key, CacheReadTypeDefault)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user