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

Function TestAverageAccessTimeWhenUpdateWithNewSpace

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

Source from the content-addressed store, hash-verified

608}
609
610func TestAverageAccessTimeWhenUpdateWithNewSpace(t *testing.T) {
611 cache := NewCache(1024)
612
613 key := []byte("test-key")
614 valueLong := []byte("very-long-de-value")
615 valueShort := []byte("short")
616
617 err := cache.Set(key, valueShort, 0)
618 if err != nil {
619 t.Fatal("err should be nil")
620 }
621 now := time.Now().Unix()
622 aat := cache.AverageAccessTime()
623 if (now - aat) > 1 {
624 t.Fatalf("track average access time error, now:%d, aat:%d", now, aat)
625 }
626
627 time.Sleep(time.Second * 4)
628 err = cache.Set(key, valueLong, 0)
629 if err != nil {
630 t.Fatal("err should be nil")
631 }
632 now = time.Now().Unix()
633 aat = cache.AverageAccessTime()
634 if (now - aat) > 2 {
635 t.Fatalf("track average access time error, now:%d, aat:%d", now, aat)
636 }
637}
638
639func TestLargeEntry(t *testing.T) {
640 cacheSize := 512 * 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…