MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestPutStreamErrorMidStream

Function TestPutStreamErrorMidStream

cmd/cache-proxy/cache_test.go:256–276  ·  view source on GitHub ↗

TestPutStreamErrorMidStream verifies that a reader failing mid-body leaves no servable entry, no LRU accounting, and no temp-file leak.

(t *testing.T)

Source from the content-addressed store, hash-verified

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
278func TestDiskCacheStartupCountsCommittedBytesAsReclaimable(t *testing.T) {
279 dir := t.TempDir()

Callers

nothing calls this directly

Calls 5

newTestCacheFunction · 0.85
tmpDirEntriesFunction · 0.85
PutStreamMethod · 0.80
HasMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected