(t *testing.T)
| 727 | } |
| 728 | |
| 729 | func 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 | |
| 757 | func TestIteratorExpireAt(t *testing.T) { |
| 758 | cache := NewCache(1024) |
nothing calls this directly
no test coverage detected
searching dependent graphs…