TestPutStreamErrorMidStream verifies that a reader failing mid-body leaves no servable entry, no LRU accounting, and no temp-file leak.
(t *testing.T)
| 254 | when time.Time |
| 255 | }{ |
| 256 | {strings.Repeat("7", 64), time.Now().Add(-2 * time.Hour)}, |
| 257 | {strings.Repeat("8", 64), time.Now().Add(-time.Hour)}, |
| 258 | {strings.Repeat("9", 64), time.Now()}, |
| 259 | } |
| 260 | for _, entry := range entries { |
| 261 | path := filepath.Join(dir, entry.key) |
| 262 | if err := os.WriteFile(path, []byte("x"), 0600); err != nil { |
| 263 | t.Fatal(err) |
| 264 | } |
| 265 | if err := os.Chtimes(path, entry.when, entry.when); err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
| 268 | } |
| 269 | c, err := NewDiskCache(dir, 100, DiskCacheOptions{MaxEntries: 3, hardMaxEntries: 2}) |
| 270 | if err != nil { |
| 271 | t.Fatal(err) |
| 272 | } |
| 273 | if c.order.Len() != 2 || c.Has(entries[0].key) || !c.Has(entries[1].key) || !c.Has(entries[2].key) { |
| 274 | t.Fatalf("startup scan did not retain newest two entries") |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func TestDiskCacheStartupCountsCommittedBytesAsReclaimable(t *testing.T) { |
| 279 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected