MCPcopy
hub / github.com/prometheus/node_exporter / runCommandAndTests

Function runCommandAndTests

node_exporter_test.go:129–154  ·  view source on GitHub ↗
(cmd *exec.Cmd, address string, fn func(pid int) error)

Source from the content-addressed store, hash-verified

127}
128
129func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) error {
130 if err := cmd.Start(); err != nil {
131 return fmt.Errorf("failed to start command: %s", err)
132 }
133 time.Sleep(50 * time.Millisecond)
134 for i := range 10 {
135 if err := queryExporter(address); err == nil {
136 break
137 }
138 time.Sleep(500 * time.Millisecond)
139 if cmd.Process == nil || i == 9 {
140 return fmt.Errorf("can't start command")
141 }
142 }
143
144 errc := make(chan error)
145 go func(pid int) {
146 errc <- fn(pid)
147 }(cmd.Process.Pid)
148
149 err := <-errc
150 if cmd.Process != nil {
151 cmd.Process.Kill()
152 }
153 return err
154}

Callers 2

TestFileDescriptorLeakFunction · 0.85

Calls 1

queryExporterFunction · 0.85

Tested by

no test coverage detected