(t *testing.T)
| 671 | } |
| 672 | |
| 673 | func TestCacheRestStats(t *testing.T) { |
| 674 | t.Parallel() |
| 675 | |
| 676 | // given |
| 677 | cache, _ := New(context.Background(), Config{ |
| 678 | Shards: 8, |
| 679 | LifeWindow: time.Second, |
| 680 | MaxEntriesInWindow: 1, |
| 681 | MaxEntrySize: 256, |
| 682 | }) |
| 683 | |
| 684 | // when |
| 685 | for i := 0; i < 100; i++ { |
| 686 | cache.Set(fmt.Sprintf("key%d", i), []byte("value")) |
| 687 | } |
| 688 | |
| 689 | for i := 0; i < 10; i++ { |
| 690 | value, err := cache.Get(fmt.Sprintf("key%d", i)) |
| 691 | noError(t, err) |
| 692 | assertEqual(t, string(value), "value") |
| 693 | } |
| 694 | for i := 100; i < 110; i++ { |
| 695 | _, err := cache.Get(fmt.Sprintf("key%d", i)) |
| 696 | assertEqual(t, ErrEntryNotFound, err) |
| 697 | } |
| 698 | for i := 10; i < 20; i++ { |
| 699 | err := cache.Delete(fmt.Sprintf("key%d", i)) |
| 700 | noError(t, err) |
| 701 | } |
| 702 | for i := 110; i < 120; i++ { |
| 703 | err := cache.Delete(fmt.Sprintf("key%d", i)) |
| 704 | assertEqual(t, ErrEntryNotFound, err) |
| 705 | } |
| 706 | |
| 707 | stats := cache.Stats() |
| 708 | assertEqual(t, stats.Hits, int64(10)) |
| 709 | assertEqual(t, stats.Misses, int64(10)) |
| 710 | assertEqual(t, stats.DelHits, int64(10)) |
| 711 | assertEqual(t, stats.DelMisses, int64(10)) |
| 712 | |
| 713 | //then |
| 714 | cache.ResetStats() |
| 715 | stats = cache.Stats() |
| 716 | assertEqual(t, stats.Hits, int64(0)) |
| 717 | assertEqual(t, stats.Misses, int64(0)) |
| 718 | assertEqual(t, stats.DelHits, int64(0)) |
| 719 | assertEqual(t, stats.DelMisses, int64(0)) |
| 720 | } |
| 721 | |
| 722 | func TestCacheDel(t *testing.T) { |
| 723 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…