aboutsummaryrefslogtreecommitdiff
path: root/node_exporter_test.go
diff options
context:
space:
mode:
authorMartín Ferrari <tincho@debian.org>2017-08-19 11:37:57 +0200
committerMartín Ferrari <tincho@debian.org>2017-08-19 11:37:57 +0200
commit2cd49eb020061df846f0e20bc0cbe77020fc19b9 (patch)
tree6596775772aef92f7014c47b5557e49103b64505 /node_exporter_test.go
parent8839640cd1e9af5f66d90d8709ae65b2f370e866 (diff)
downloadprometheus_node_collector-2cd49eb020061df846f0e20bc0cbe77020fc19b9.tar.bz2
prometheus_node_collector-2cd49eb020061df846f0e20bc0cbe77020fc19b9.tar.xz
prometheus_node_collector-2cd49eb020061df846f0e20bc0cbe77020fc19b9.zip
Fix path and timing issues with integration tests.
Diffstat (limited to 'node_exporter_test.go')
-rw-r--r--node_exporter_test.go33
1 files changed, 15 insertions, 18 deletions
diff --git a/node_exporter_test.go b/node_exporter_test.go
index 538ef1a..a41ee97 100644
--- a/node_exporter_test.go
+++ b/node_exporter_test.go
@@ -13,8 +13,10 @@ import (
13 "github.com/prometheus/procfs" 13 "github.com/prometheus/procfs"
14) 14)
15 15
16var (
17 binary = filepath.Join(os.Getenv("GOPATH"), "bin/node_exporter")
18)
16const ( 19const (
17 binary = "./node_exporter"
18 address = "localhost:19100" 20 address = "localhost:19100"
19) 21)
20 22
@@ -54,7 +56,7 @@ func TestFileDescriptorLeak(t *testing.T) {
54 return nil 56 return nil
55 } 57 }
56 58
57 if err := runCommandAndTests(exporter, test); err != nil { 59 if err := runCommandAndTests(exporter, address, test); err != nil {
58 t.Error(err) 60 t.Error(err)
59 } 61 }
60} 62}
@@ -83,7 +85,7 @@ func TestHandlingOfDuplicatedMetrics(t *testing.T) {
83 return queryExporter(address) 85 return queryExporter(address)
84 } 86 }
85 87
86 if err := runCommandAndTests(exporter, test); err != nil { 88 if err := runCommandAndTests(exporter, address, test); err != nil {
87 t.Error(err) 89 t.Error(err)
88 } 90 }
89} 91}
@@ -106,27 +108,22 @@ func queryExporter(address string) error {
106 return nil 108 return nil
107} 109}
108 110
109func runCommandAndTests(cmd *exec.Cmd, fn func(pid int) error) error { 111func runCommandAndTests(cmd *exec.Cmd, address string, fn func(pid int) error) error {
110 if err := cmd.Start(); err != nil { 112 if err := cmd.Start(); err != nil {
111 return fmt.Errorf("failed to start command: %s", err) 113 return fmt.Errorf("failed to start command: %s", err)
112 } 114 }
113 115 time.Sleep(50 * time.Millisecond)
114 errc := make(chan error) 116 for i := 0; i < 10; i++ {
115 go func() { 117 if err := queryExporter(address); err == nil {
116 if err := cmd.Wait(); err != nil { 118 break
117 errc <- fmt.Errorf("execution of command failed: %s", err) 119 }
118 } else { 120 time.Sleep(500 * time.Millisecond)
119 errc <- nil 121 if cmd.Process== nil || i == 9 {
122 return fmt.Errorf("can't start command")
120 } 123 }
121 }()
122
123 // Allow the process to start before running any tests.
124 select {
125 case err := <-errc:
126 return err
127 case <-time.After(100 * time.Millisecond):
128 } 124 }
129 125
126 errc := make(chan error)
130 go func(pid int) { 127 go func(pid int) {
131 errc <- fn(pid) 128 errc <- fn(pid)
132 }(cmd.Process.Pid) 129 }(cmd.Process.Pid)