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

Function TestPutStreamOverwrite

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

TestPutStreamOverwrite verifies that re-streaming a key replaces it without double-counting currentSize or leaving a duplicate LRU entry (finding #2).

(t *testing.T)

Source from the content-addressed store, hash-verified

278func TestDiskCacheStartupCountsCommittedBytesAsReclaimable(t *testing.T) {
279 dir := t.TempDir()
280 keys := []string{strings.Repeat("a", 64), strings.Repeat("b", 64)}
281 for _, key := range keys {
282 if err := os.WriteFile(filepath.Join(dir, key), make([]byte, 400), 0600); err != nil {
283 t.Fatal(err)
284 }
285 }
286
287 c, err := NewDiskCache(dir, 80, DiskCacheOptions{
288 MaxEntries: 2,
289 CapacityProvider: func(string) (diskSpace, error) {
290 // The disk is 80% full only because of the two committed cache files.
291 return diskSpace{TotalBytes: 1000, FreeBytes: 200}, nil
292 },
293 })
294 if err != nil {
295 t.Fatal(err)
296 }
297 if c.currentSize != 800 || c.maxBytes != 800 {
298 t.Fatalf("startup cache size/capacity = %d/%d, want 800/800; committed entries must not be mistaken for external disk use", c.currentSize, c.maxBytes)
299 }
300 for _, key := range keys {
301 if !c.Has(key) {
302 t.Fatalf("startup pruned committed cache key %s", key)
303 }
304 }
305}
306
307func TestDiskCacheScanSeparatesTemporaryInvalidAndCommittedFiles(t *testing.T) {
308 dir := t.TempDir()
309 key := strings.Repeat("c", 64)
310 if err := os.WriteFile(filepath.Join(dir, key), []byte("committed"), 0600); err != nil {
311 t.Fatal(err)

Callers

nothing calls this directly

Calls 4

newTestCacheFunction · 0.85
PutStreamMethod · 0.80
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected