MCPcopy
hub / github.com/tailscale/tailscale / TestCurrentFileDescriptors

Function TestCurrentFileDescriptors

metrics/metrics_test.go:35–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestCurrentFileDescriptors(t *testing.T) {
36 if runtime.GOOS != "linux" {
37 t.Skipf("skipping on %v", runtime.GOOS)
38 }
39 n := CurrentFDs()
40 if n < 3 {
41 t.Fatalf("got %v; want >= 3", n)
42 }
43
44 err := tstest.MinAllocsPerRun(t, 0, func() {
45 n = CurrentFDs()
46 })
47 if err != nil {
48 t.Fatal(err)
49 }
50
51 // Open some FDs.
52 const extra = 10
53 for i := range extra {
54 f, err := os.Open("/proc/self/stat")
55 if err != nil {
56 t.Fatal(err)
57 }
58 defer f.Close()
59 t.Logf("fds for #%v = %v", i, CurrentFDs())
60 }
61
62 n2 := CurrentFDs()
63 if n2 < n+extra {
64 t.Errorf("fds changed from %v => %v, want to %v", n, n2, n+extra)
65 }
66}
67
68func BenchmarkCurrentFileDescriptors(b *testing.B) {
69 b.ReportAllocs()

Callers

nothing calls this directly

Calls 9

MinAllocsPerRunFunction · 0.92
CurrentFDsFunction · 0.85
SkipfMethod · 0.65
FatalfMethod · 0.65
FatalMethod · 0.65
CloseMethod · 0.65
LogfMethod · 0.65
ErrorfMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…