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

Function TestLoadingExpired

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

Source from the content-addressed store, hash-verified

396}
397
398func TestLoadingExpired(t *testing.T) {
399 lc := lru.NewLRU[string, string](0, nil, time.Millisecond*5)
400
401 lc.Add("key1", "val1")
402 if lc.Len() != 1 {
403 t.Fatalf("length differs from expected")
404 }
405
406 v, ok := lc.Peek("key1")
407 if v != "val1" {
408 t.Fatalf("value differs from expected")
409 }
410 if !ok {
411 t.Fatalf("should be true")
412 }
413
414 v, ok = lc.Get("key1")
415 if v != "val1" {
416 t.Fatalf("value differs from expected")
417 }
418 if !ok {
419 t.Fatalf("should be true")
420 }
421
422 for {
423 result, ok := lc.Get("key1")
424 if ok && result == "" {
425 t.Fatalf("ok should return a result")
426 }
427 if !ok {
428 break
429 }
430 }
431
432 time.Sleep(time.Millisecond * 100) // wait for expiration reaper
433 if lc.Len() != 0 {
434 t.Fatalf("length differs from expected")
435 }
436
437 v, ok = lc.Peek("key1")
438 if v != "" {
439 t.Fatalf("should be empty")
440 }
441 if ok {
442 t.Fatalf("should be false")
443 }
444
445 v, ok = lc.Get("key1")
446 if v != "" {
447 t.Fatalf("should be empty")
448 }
449 if ok {
450 t.Fatalf("should be false")
451 }
452}
453
454func TestLRURemoveOldest(t *testing.T) {
455 lc := lru.NewLRU[string, string](2, nil, 0)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected