MCPcopy Create free account
hub / github.com/Azure/peerd / TestSyncMapAddEvict

Function TestSyncMapAddEvict

pkg/cache/syncmap_test.go:18–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16}
17
18func TestSyncMapAddEvict(t *testing.T) {
19 sm := NewSyncMap(100)
20 sm.evictionPercentage = 10
21 var wg sync.WaitGroup
22 addEntry := func(key string, value int) {
23 sm.Set(key, value)
24 wg.Done()
25 }
26
27 wg.Add(100)
28 for i := 0; i < 100; i++ {
29 go addEntry(fmt.Sprintf("%d", i), i)
30 }
31 wg.Wait()
32
33 if mapLen := len(*sm.mapObj); mapLen != 100 {
34 t.Fatalf("unexpected length of map after adding to capacity: %d", mapLen)
35 }
36
37 sm.Set("200", 200) // Now it's beyond the map capacity. 10% of entries will be evicted
38 if mapLen := len(*sm.mapObj); mapLen != 91 {
39 t.Fatalf("unexpected length of map after adding beyond capacity: %d", mapLen)
40 }
41}
42
43func TestSyncMapAddDelete(t *testing.T) {
44 sm := NewSyncMap(10)

Callers

nothing calls this directly

Calls 2

SetMethod · 0.95
NewSyncMapFunction · 0.85

Tested by

no test coverage detected