(t *testing.T)
| 538 | } |
| 539 | |
| 540 | func TestTouch(t *testing.T) { |
| 541 | cache := NewCache(1024) |
| 542 | key1 := []byte("abcd") |
| 543 | val1 := []byte("efgh") |
| 544 | key2 := []byte("ijkl") |
| 545 | val2 := []byte("mnop") |
| 546 | err := cache.Set(key1, val1, 1) |
| 547 | if err != nil { |
| 548 | t.Error("err should be nil", err.Error()) |
| 549 | } |
| 550 | err = cache.Set(key2, val2, 1) |
| 551 | if err != nil { |
| 552 | t.Error("err should be nil", err.Error()) |
| 553 | } |
| 554 | if touched := cache.TouchedCount(); touched != 0 { |
| 555 | t.Fatalf("touched count should be 0, but %d returned", touched) |
| 556 | } |
| 557 | err = cache.Touch(key1, 2) |
| 558 | if err != nil { |
| 559 | t.Error("err should be nil", err.Error()) |
| 560 | } |
| 561 | time.Sleep(time.Second) |
| 562 | ttl, err := cache.TTL(key1) |
| 563 | if err != nil { |
| 564 | t.Error("err should be nil", err.Error()) |
| 565 | } |
| 566 | if ttl != 1 { |
| 567 | t.Fatalf("ttl should be 1, but %d returned", ttl) |
| 568 | } |
| 569 | if touched := cache.TouchedCount(); touched != 1 { |
| 570 | t.Fatalf("touched count should be 1, but %d returned", touched) |
| 571 | } |
| 572 | err = cache.Touch(key2, 2) |
| 573 | if err != ErrNotFound { |
| 574 | t.Error("error should be ErrNotFound after expiring") |
| 575 | } |
| 576 | if touched := cache.TouchedCount(); touched != 1 { |
| 577 | t.Fatalf("touched count should be 1, but %d returned", touched) |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | func TestAverageAccessTimeWhenUpdateInplace(t *testing.T) { |
| 582 | cache := NewCache(1024) |
nothing calls this directly
no test coverage detected
searching dependent graphs…