mirror of
https://github.com/rancher/steve.git
synced 2025-08-11 03:01:38 +00:00
Fix race in accessstore test (#466)
This commit is contained in:
parent
5cdbd29ebe
commit
8ae74491e7
@ -315,24 +315,27 @@ func TestAccessStore_AccessFor_concurrent(t *testing.T) {
|
|||||||
|
|
||||||
const n = 5 // observation showed cases with up to 5 (or more) concurrent queries for the same user
|
const n = 5 // observation showed cases with up to 5 (or more) concurrent queries for the same user
|
||||||
|
|
||||||
|
ids := make([]string, n)
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var id string
|
for i := range n {
|
||||||
for range n {
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
<-wait
|
<-wait
|
||||||
id = store.AccessFor(testUser).ID
|
ids[i] = store.AccessFor(testUser).ID
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
close(wait)
|
close(wait)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
if got, want := len(slices.Compact(ids)), 1; got != want {
|
||||||
|
t.Errorf("Unexpected number of ids: got %d, want %d", got, want)
|
||||||
|
}
|
||||||
if got, want := len(asCache.setCalls), 1; got != want {
|
if got, want := len(asCache.setCalls), 1; got != want {
|
||||||
t.Errorf("Unexpected number of cache entries: got %d, want %d", got, want)
|
t.Errorf("Unexpected number of cache entries: got %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
if got, want := asCache.setCalls[id], 1; got != want {
|
if got, want := asCache.setCalls[ids[0]], 1; got != want {
|
||||||
t.Errorf("Unexpected number of calls to cache.Set(): got %d, want %d", got, want)
|
t.Errorf("Unexpected number of calls to cache.Set(): got %d, want %d", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user