|
|
@ -13,8 +13,10 @@ import (
|
|
|
|
"github.com/prometheus/procfs"
|
|
|
|
"github.com/prometheus/procfs"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
binary = filepath.Join(os.Getenv("GOPATH"), "bin/node_exporter")
|
|
|
|
|
|
|
|
)
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
binary = "./node_exporter"
|
|
|
|
|
|
|
|
address = "localhost:19100"
|
|
|
|
address = "localhost:19100"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -54,7 +56,7 @@ func TestFileDescriptorLeak(t *testing.T) {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := runCommandAndTests(exporter, test); err != nil {
|
|
|
|
if err := runCommandAndTests(exporter, address, test); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,7 +85,7 @@ func TestHandlingOfDuplicatedMetrics(t *testing.T) {
|
|
|
|
return queryExporter(address)
|
|
|
|
return queryExporter(address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := runCommandAndTests(exporter, test); err != nil {
|
|
|
|
if err := runCommandAndTests(exporter, address, test); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -106,27 +108,22 @@ func queryExporter(address string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func runCommandAndTests(cmd *exec.Cmd, fn func(pid int) error) error {
|
|
|
|
func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) error {
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
return fmt.Errorf("failed to start command: %s", err)
|
|
|
|
return fmt.Errorf("failed to start command: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
errc := make(chan error)
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
go func() {
|
|
|
|
if err := queryExporter(address); err == nil {
|
|
|
|
if err := cmd.Wait(); err != nil {
|
|
|
|
break
|
|
|
|
errc <- fmt.Errorf("execution of command failed: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
errc <- nil
|
|
|
|
if cmd.Process== nil || i == 9 {
|
|
|
|
|
|
|
|
return fmt.Errorf("can't start command")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Allow the process to start before running any tests.
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
|
|
|
case err := <-errc:
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errc := make(chan error)
|
|
|
|
go func(pid int) {
|
|
|
|
go func(pid int) {
|
|
|
|
errc <- fn(pid)
|
|
|
|
errc <- fn(pid)
|
|
|
|
}(cmd.Process.Pid)
|
|
|
|
}(cmd.Process.Pid)
|
|
|
|