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

Function TestIterator

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

Source from the content-addressed store, hash-verified

727}
728
729func TestIterator(t *testing.T) {
730 cache := NewCache(1024)
731 count := 10000
732 for i := 0; i < count; i++ {
733 err := cache.Set([]byte(fmt.Sprintf("%d", i)), []byte(fmt.Sprintf("val%d", i)), 0)
734 if err != nil {
735 t.Error(err)
736 }
737 }
738 // Set some value that expires to make sure expired entry is not returned.
739 cache.Set([]byte("abc"), []byte("def"), 1)
740 time.Sleep(2 * time.Second)
741 it := cache.NewIterator()
742 for i := 0; i < count; i++ {
743 entry := it.Next()
744 if entry == nil {
745 t.Fatalf("entry is nil for %d", i)
746 }
747 if string(entry.Value) != "val"+string(entry.Key) {
748 t.Fatalf("entry key value not match %s %s", entry.Key, entry.Value)
749 }
750 }
751 e := it.Next()
752 if e != nil {
753 t.Fail()
754 }
755}
756
757func TestIteratorExpireAt(t *testing.T) {
758 cache := NewCache(1024)

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
NewIteratorMethod · 0.95
NextMethod · 0.95
NewCacheFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…