MCPcopy
hub / github.com/coocood/freecache / TestAverageAccessTimeWhenUpdateInplace

Function TestAverageAccessTimeWhenUpdateInplace

cache_test.go:581–608  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

579}
580
581func TestAverageAccessTimeWhenUpdateInplace(t *testing.T) {
582 cache := NewCache(1024)
583
584 key := []byte("test-key")
585 valueLong := []byte("very-long-de-value")
586 valueShort := []byte("short")
587
588 err := cache.Set(key, valueLong, 0)
589 if err != nil {
590 t.Fatal("err should be nil")
591 }
592 now := time.Now().Unix()
593 aat := cache.AverageAccessTime()
594 if (now - aat) > 1 {
595 t.Fatalf("track average access time error, now:%d, aat:%d", now, aat)
596 }
597
598 time.Sleep(time.Second * 4)
599 err = cache.Set(key, valueShort, 0)
600 if err != nil {
601 t.Fatal("err should be nil")
602 }
603 now = time.Now().Unix()
604 aat = cache.AverageAccessTime()
605 if (now - aat) > 1 {
606 t.Fatalf("track average access time error, now:%d, aat:%d", now, aat)
607 }
608}
609
610func TestAverageAccessTimeWhenUpdateWithNewSpace(t *testing.T) {
611 cache := NewCache(1024)

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
AverageAccessTimeMethod · 0.95
NewCacheFunction · 0.85
NowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…