-
Notifications
You must be signed in to change notification settings - Fork 480
/
Copy pathfd_test.go
34 lines (29 loc) · 1020 Bytes
/
fd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2021 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
package vfs
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestFileWrappersHaveFd(t *testing.T) {
// Use the real filesystem so that we can test vfs.Default, which returns
// files with Fd().
tmpf, err := os.CreateTemp("", "pebble-db-fd-file")
require.NoError(t, err)
filename := tmpf.Name()
defer os.Remove(filename)
// File wrapper case 1: Check if diskHealthCheckingFile has Fd().
fs2, closer := WithDiskHealthChecks(Default, 10*time.Second,
func(s string, duration time.Duration) {})
defer closer.Close()
f2, err := fs2.Open(filename)
require.NoError(t, err)
require.NotZero(t, f2.Fd())
// File wrapper case 2: Check if syncingFile has Fd().
f3 := NewSyncingFile(f2, SyncingFileOptions{BytesPerSync: 8 << 10 /* 8 KB */})
require.NotZero(t, f3.Fd())
require.NoError(t, f2.Close())
}