Merge pull request #94537 from knight42/fix/TestCacheNoConcurrentGet

test(azure): Deflake TestCacheNoConcurrentGet
This commit is contained in:
Kubernetes Prow Robot 2020-09-04 16:59:41 -07:00 committed by GitHub
commit 0f466ba177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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{

View File

@ -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()