MCPcopy Index your code
hub / github.com/prometheus/node_exporter / TestReadProcessStatus

Function TestReadProcessStatus

collector/processes_linux_test.go:27–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestReadProcessStatus(t *testing.T) {
28 if _, err := kingpin.CommandLine.Parse([]string{"--path.procfs", "fixtures/proc"}); err != nil {
29 t.Fatal(err)
30 }
31 want := 1
32 fs, err := procfs.NewFS(*procPath)
33 if err != nil {
34 t.Errorf("failed to open procfs: %v", err)
35 }
36 c := processCollector{fs: fs, logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
37 pids, states, threads, _, err := c.getAllocatedThreads()
38 if err != nil {
39 t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err)
40 }
41 if threads < want {
42 t.Fatalf("Current threads: %d Shouldn't be less than wanted %d", threads, want)
43 }
44 if states == nil {
45
46 t.Fatalf("Process states cannot be nil %v:", states)
47 }
48 maxPid, err := readUintFromFile(procFilePath("sys/kernel/pid_max"))
49 if err != nil {
50 t.Fatalf("Unable to retrieve limit number of maximum pids allowed %v\n", err)
51 }
52 if uint64(pids) > maxPid || pids == 0 {
53 t.Fatalf("Total running pids cannot be greater than %d or equals to 0", maxPid)
54 }
55}

Callers

nothing calls this directly

Calls 3

getAllocatedThreadsMethod · 0.95
readUintFromFileFunction · 0.85
procFilePathFunction · 0.85

Tested by

no test coverage detected