diff options
| author | 2026-06-09 05:15:58 +0000 | |
|---|---|---|
| committer | 2026-06-09 05:15:58 +0000 | |
| commit | 55676a35757bcbf2fa40cc3fd144ba412c65b658 (patch) | |
| tree | 4c75c8497941d7b8c8c5530f5467bf42610c3f10 /internal/clock/concurrent_test.go | |
| parent | internal/lru: Add sharded CLOCK (diff) | |
| signature | No signature | |
internal/cache: add (and move clock to internal/cache/clock)
Diffstat (limited to 'internal/clock/concurrent_test.go')
| -rw-r--r-- | internal/clock/concurrent_test.go | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/internal/clock/concurrent_test.go b/internal/clock/concurrent_test.go deleted file mode 100644 index 86283a9b..00000000 --- a/internal/clock/concurrent_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package clock //nolint:testpackage - -import ( - "sync" - "testing" -) - -func keyValue(key int) int { - return key*1000003 + 7 -} - -func TestConcurrentStress(t *testing.T) { - t.Parallel() - - const ( - maxWeight = 512 - keys = 400 - workers = 8 - rounds = 5000 - ) - - cache := New(maxWeight, func(_ int, _ int) uint64 { return 1 }) - - var wg sync.WaitGroup - - for worker := range workers { - wg.Go(func() { - for i := range rounds { - key := (worker*7 + i) % keys - - switch i % 4 { - case 0, 1: - cache.Add(key, keyValue(key)) - case 2: - if got, ok := cache.Get(key); ok && got != keyValue(key) { - t.Errorf("Get(%d) = %d, want %d", key, got, keyValue(key)) - } - case 3: - if got, ok := cache.Peek(key); ok && got != keyValue(key) { - t.Errorf("Peek(%d) = %d, want %d", key, got, keyValue(key)) - } - } - } - }) - } - - wg.Wait() - - checkCache(t, cache) - - if got := cache.Weight(); got > maxWeight { - t.Fatalf("weight %d exceeds max %d", got, maxWeight) - } -} - -func TestReadDuringEviction(t *testing.T) { - t.Parallel() - - const ( - maxWeight = 8 - hot = 64 - writers = 2 - readers = 6 - rounds = 20000 - ) - - cache := New(maxWeight, func(_ int, _ int) uint64 { return 1 }) - - var wg sync.WaitGroup - - for range writers { - wg.Go(func() { - for i := range rounds { - key := i % hot - cache.Add(key, keyValue(key)) - } - }) - } - - for range readers { - wg.Go(func() { - for i := range rounds { - key := i % hot - - if got, ok := cache.Get(key); ok && got != keyValue(key) { - t.Errorf("Get(%d) = %d, want %d", key, got, keyValue(key)) - } - - if got, ok := cache.Peek(key); ok && got != keyValue(key) { - t.Errorf("Peek(%d) = %d, want %d", key, got, keyValue(key)) - } - } - }) - } - - wg.Wait() - - checkCache(t, cache) - - if got := cache.Weight(); got > maxWeight { - t.Fatalf("weight %d exceeds max %d", got, maxWeight) - } -} |
