(t *testing.T)
| 755 | } |
| 756 | |
| 757 | func TestIteratorExpireAt(t *testing.T) { |
| 758 | cache := NewCache(1024) |
| 759 | expireSecond := uint32(5) |
| 760 | // Set some value that expires to make sure expired entry is not returned. |
| 761 | cache.Set([]byte("no_expire"), []byte("def"), 0) |
| 762 | cache.Set([]byte("has_expire"), []byte("exp"), int(expireSecond)) |
| 763 | |
| 764 | it := cache.NewIterator() |
| 765 | for { |
| 766 | next := it.Next() |
| 767 | if next == nil { |
| 768 | break |
| 769 | } |
| 770 | if string(next.Key) == "no_expire" && next.ExpireAt != 0 { |
| 771 | t.Fatalf("no_expire's ExpireAt should be 0") |
| 772 | } |
| 773 | expectExpireAt := uint32(time.Now().Unix()) + expireSecond |
| 774 | if string(next.Key) == "has_expire" && next.ExpireAt != expectExpireAt { |
| 775 | t.Fatalf("has_expire's ExpireAt should be 10,actually is %d", next.ExpireAt) |
| 776 | } |
| 777 | } |
| 778 | time.Sleep(time.Duration(expireSecond) * time.Second) |
| 779 | it2 := cache.NewIterator() |
| 780 | for { |
| 781 | next := it2.Next() |
| 782 | if next == nil { |
| 783 | return |
| 784 | } |
| 785 | if string(next.Key) == "no_expire" && next.ExpireAt != 0 { |
| 786 | t.Fatalf("no_expire's ExpireAt should be 0") |
| 787 | } |
| 788 | if string(next.Key) == "has_expire" { |
| 789 | t.Fatalf("has_expire should expired") |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | func TestSetLargerEntryDeletesWrongEntry(t *testing.T) { |
| 795 | cachesize := 512 * 1024 |
nothing calls this directly
no test coverage detected
searching dependent graphs…