mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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{
|
heap.Push(&c.heap, &expiringHeapEntry{
|
||||||
key: key,
|
key: key,
|
||||||
generation: c.generation,
|
|
||||||
expiry: expiry,
|
expiry: expiry,
|
||||||
|
generation: c.generation,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,13 +158,13 @@ func (c *Expiring) gc(now time.Time) {
|
|||||||
|
|
||||||
type expiringHeapEntry struct {
|
type expiringHeapEntry struct {
|
||||||
key interface{}
|
key interface{}
|
||||||
generation uint64
|
|
||||||
expiry time.Time
|
expiry time.Time
|
||||||
|
generation uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// expiringHeap is a min-heap ordered by expiration time of it's entries. The
|
// expiringHeap is a min-heap ordered by expiration time of its entries. The
|
||||||
// expiring cache uses this as a priority queue efficiently organize entries to
|
// expiring cache uses this as a priority queue to efficiently organize entries
|
||||||
// be garbage collected once they expire.
|
// which will be garbage collected once they expire.
|
||||||
type expiringHeap []*expiringHeapEntry
|
type expiringHeap []*expiringHeapEntry
|
||||||
|
|
||||||
var _ heap.Interface = &expiringHeap{}
|
var _ heap.Interface = &expiringHeap{}
|
||||||
|
@ -264,6 +264,7 @@ func TestStressExpiringCache(t *testing.T) {
|
|||||||
for i := 0; i < 256; i++ {
|
for i := 0; i < 256; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
rand := rand.New(rand.NewSource(rand.Int63()))
|
rand := rand.New(rand.NewSource(rand.Int63()))
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -273,11 +274,18 @@ func TestStressExpiringCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
key := keys[rand.Intn(numKeys)]
|
key := keys[rand.Intn(numKeys)]
|
||||||
if _, ok := cache.Get(key); !ok {
|
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