MCPcopy
hub / github.com/go-gorm/gorm / TestLRUWithPurgeEnforcedBySize

Function TestLRUWithPurgeEnforcedBySize

tests/lru_test.go:328–349  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

326}
327
328func TestLRUWithPurgeEnforcedBySize(t *testing.T) {
329 lc := lru.NewLRU[string, string](10, nil, time.Hour)
330
331 for i := 0; i < 100; i++ {
332 i := i
333 lc.Add(fmt.Sprintf("key%d", i), fmt.Sprintf("val%d", i))
334 v, ok := lc.Get(fmt.Sprintf("key%d", i))
335 if v != fmt.Sprintf("val%d", i) {
336 t.Fatalf("value differs from expected")
337 }
338 if !ok {
339 t.Fatalf("should be true")
340 }
341 if lc.Len() > 20 {
342 t.Fatalf("length should be less than 20")
343 }
344 }
345
346 if lc.Len() != 10 {
347 t.Fatalf("length differs from expected")
348 }
349}
350
351func TestLRUConcurrency(t *testing.T) {
352 lc := lru.NewLRU[string, string](0, nil, 0)

Callers

nothing calls this directly

Calls 4

NewLRUFunction · 0.92
AddMethod · 0.80
LenMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected