tailscale/metrics/metrics_test.go
Will Norris 71029cea2d all: update copyright and license headers
This updates all source files to use a new standard header for copyright
and license declaration.  Notably, copyright no longer includes a date,
and we now use the standard SPDX-License-Identifier header.

This commit was done almost entirely mechanically with perl, and then
some minimal manual fixes.

Updates #6865

Signed-off-by: Will Norris <will@tailscale.com>
2023-01-27 15:36:29 -08:00

53 lines
911 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package metrics
import (
"os"
"runtime"
"testing"
"tailscale.com/tstest"
)
func TestCurrentFileDescriptors(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skipf("skipping on %v", runtime.GOOS)
}
n := CurrentFDs()
if n < 3 {
t.Fatalf("got %v; want >= 3", n)
}
err := tstest.MinAllocsPerRun(t, 0, func() {
n = CurrentFDs()
})
if err != nil {
t.Fatal(err)
}
// Open some FDs.
const extra = 10
for i := 0; i < extra; i++ {
f, err := os.Open("/proc/self/stat")
if err != nil {
t.Fatal(err)
}
defer f.Close()
t.Logf("fds for #%v = %v", i, CurrentFDs())
}
n2 := CurrentFDs()
if n2 < n+extra {
t.Errorf("fds changed from %v => %v, want to %v", n, n2, n+extra)
}
}
func BenchmarkCurrentFileDescriptors(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = CurrentFDs()
}
}