(t *testing.T)
| 33 | } |
| 34 | |
| 35 | func 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 | |
| 68 | func BenchmarkCurrentFileDescriptors(b *testing.B) { |
| 69 | b.ReportAllocs() |
nothing calls this directly
no test coverage detected
searching dependent graphs…