diff --git a/cache_test.go b/cache_test.go index 2972707..671161e 100644 --- a/cache_test.go +++ b/cache_test.go @@ -246,7 +246,7 @@ func TestCache_EstimatedSize(t *testing.T) { }) wg.Go(func() error { defer cfn() - for i := 0; i < 1000000; i++ { + for i := 0; i < 1200; i++ { if i%2 == 0 { client.Set(i, 1, 1) } else { @@ -256,6 +256,8 @@ func TestCache_EstimatedSize(t *testing.T) { return nil }) require.Nil(t, wg.Wait()) + client.Wait() + require.Equal(t, 500, client.EstimatedSize()) } func TestCache_Doorkeeper(t *testing.T) { diff --git a/internal/store.go b/internal/store.go index d12b9ef..139eda4 100644 --- a/internal/store.go +++ b/internal/store.go @@ -463,7 +463,7 @@ func (s *Store[K, V]) Len() int { func (s *Store[K, V]) EstimatedSize() int { s.policyMu.Lock() - total := s.policy.slru.protected.Len() + s.policy.slru.probation.Len() + total := s.policy.window.Len() + s.policy.slru.protected.Len() + s.policy.slru.probation.Len() s.policyMu.Unlock() return total }