(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func 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 | |
| 43 | func TestSyncMapAddDelete(t *testing.T) { |
| 44 | sm := NewSyncMap(10) |
nothing calls this directly
no test coverage detected