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

Function TestOpenCountsHitOpenFileDoesNot

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

TestOpenCountsHitOpenFileDoesNot locks in the metric split: serving a hit via Open records a cache hit; serving a freshly-fetched miss via openFile does not (otherwise misses would be double-counted as hits).

(t *testing.T)

Source from the content-addressed store, hash-verified

335 if _, err := os.Stat(filepath.Join(dir, tmpSubdir, "interrupted")); !os.IsNotExist(err) {
336 t.Fatalf("temporary file still exists after startup: %v", err)
337 }
338 if _, err := os.Stat(invalid); err != nil {
339 t.Fatalf("unrelated file should remain external disk use: %v", err)
340 }
341 if got := counterValue(t, cacheTemporaryFilesRemovedTotal) - beforeTemporary; got != 1 {
342 t.Fatalf("temporary cleanup count = %v, want 1", got)
343 }
344 if got := counterValue(t, cacheStartupInvalidFilesTotal) - beforeInvalid; got != 1 {
345 t.Fatalf("invalid file count = %v, want 1", got)
346 }
347}
348
349func TestNewDiskCacheFailsWhenStartupScanCannotOpenDirectory(t *testing.T) {
350 scanErr := errors.New("forced startup scan open failure")
351 c, err := NewDiskCache(t.TempDir(), 80, DiskCacheOptions{
352 openScanDirectory: func(string) (cacheDirectory, error) {
353 return nil, scanErr
354 },
355 })
356 if c != nil {
357 t.Fatal("NewDiskCache returned a cache after its startup scan failed")
358 }
359 if !errors.Is(err, scanErr) {
360 t.Fatalf("NewDiskCache error = %v, want wrapped scan error", err)
361 }
362}
363
364func TestNewDiskCacheFailsWhenStartupScanStopsBeforeDirectoryIsExhausted(t *testing.T) {
365 dir := t.TempDir()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected