| 99 | } |
| 100 | |
| 101 | func TestResultCache_TTLExpiry(t *testing.T) { |
| 102 | t.Parallel() |
| 103 | |
| 104 | c := newResultCache() |
| 105 | |
| 106 | // Manually store an entry that is already expired. |
| 107 | key := cacheKey("Expired Show", 1) |
| 108 | c.entries.Store(key, cacheEntry{ |
| 109 | count: 10, |
| 110 | expires: time.Now().Add(-1 * time.Second), |
| 111 | }) |
| 112 | |
| 113 | _, ok := c.Get("Expired Show", 1) |
| 114 | if ok { |
| 115 | t.Fatal("expected cache miss for expired entry") |
| 116 | } |
| 117 | |
| 118 | // Confirm the expired entry was cleaned up. |
| 119 | if _, loaded := c.entries.Load(key); loaded { |
| 120 | t.Error("expired entry should have been deleted from map") |
| 121 | } |
| 122 | } |