mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #85386 from mikedanese/fixstresstest
cache.Expiring: fix stress test: it's not doing anything
This commit is contained in:
commit
f0b1915c3c
@ -102,8 +102,8 @@ func (c *Expiring) Set(key interface{}, val interface{}, ttl time.Duration) {
|
||||
|
||||
heap.Push(&c.heap, &expiringHeapEntry{
|
||||
key: key,
|
||||
generation: c.generation,
|
||||
expiry: expiry,
|
||||
generation: c.generation,
|
||||
})
|
||||
}
|
||||
|
||||
@ -158,13 +158,13 @@ func (c *Expiring) gc(now time.Time) {
|
||||
|
||||
type expiringHeapEntry struct {
|
||||
key interface{}
|
||||
generation uint64
|
||||
expiry time.Time
|
||||
generation uint64
|
||||
}
|
||||
|
||||
// expiringHeap is a min-heap ordered by expiration time of it's entries. The
|
||||
// expiring cache uses this as a priority queue efficiently organize entries to
|
||||
// be garbage collected once they expire.
|
||||
// expiringHeap is a min-heap ordered by expiration time of its entries. The
|
||||
// expiring cache uses this as a priority queue to efficiently organize entries
|
||||
// which will be garbage collected once they expire.
|
||||
type expiringHeap []*expiringHeapEntry
|
||||
|
||||
var _ heap.Interface = &expiringHeap{}
|
||||
|
@ -264,6 +264,7 @@ func TestStressExpiringCache(t *testing.T) {
|
||||
for i := 0; i < 256; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
rand := rand.New(rand.NewSource(rand.Int63()))
|
||||
for {
|
||||
select {
|
||||
@ -273,11 +274,18 @@ func TestStressExpiringCache(t *testing.T) {
|
||||
}
|
||||
key := keys[rand.Intn(numKeys)]
|
||||
if _, ok := cache.Get(key); !ok {
|
||||
cache.Set(key, struct{}{}, time.Second)
|
||||
cache.Set(key, struct{}{}, 50*time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
wg.Wait()
|
||||
|
||||
// trigger a GC with a set and check the cache size.
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
cache.Set("trigger", "gc", time.Second)
|
||||
if cache.Len() != 1 {
|
||||
t.Errorf("unexpected cache size: got=%d, want=1", cache.Len())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user