github.com/cockroachdb/pebble@v1.1.1-0.20240513155919-3622ade60459/vfs/fd_test.go (about) 1 // Copyright 2021 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package vfs 6 7 import ( 8 "os" 9 "testing" 10 "time" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestFileWrappersHaveFd(t *testing.T) { 16 // Use the real filesystem so that we can test vfs.Default, which returns 17 // files with Fd(). 18 tmpf, err := os.CreateTemp("", "pebble-db-fd-file") 19 require.NoError(t, err) 20 filename := tmpf.Name() 21 defer os.Remove(filename) 22 23 // File wrapper case 1: Check if diskHealthCheckingFile has Fd(). 24 fs2, closer := WithDiskHealthChecks(Default, 10*time.Second, 25 func(info DiskSlowInfo) {}) 26 defer closer.Close() 27 f2, err := fs2.Open(filename) 28 require.NoError(t, err) 29 require.NotZero(t, f2.Fd()) 30 require.NotEqual(t, f2.Fd(), InvalidFd) 31 // File wrapper case 2: Check if syncingFile has Fd(). 32 f3 := NewSyncingFile(f2, SyncingFileOptions{BytesPerSync: 8 << 10 /* 8 KB */}) 33 require.NotZero(t, f3.Fd()) 34 require.NotEqual(t, f3.Fd(), InvalidFd) 35 require.NoError(t, f2.Close()) 36 }