forked from janishjindal/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysstat_interval_test.go
44 lines (35 loc) · 951 Bytes
/
sysstat_interval_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// +build !race
// +build linux
package sysstat
import (
"os/exec"
"testing"
"time"
"github.com/influxdata/telegraf/testutil"
)
// TestInterval verifies that the correct interval is created. It is not
// run with -race option, because in that scenario interval between the two
// Gather calls is greater than wantedInterval.
func TestInterval(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test with sleep in short mode.")
}
// overwriting exec commands with mock commands
execCommand = fakeExecCommand
defer func() { execCommand = exec.Command }()
var acc testutil.Accumulator
s.interval = 0
wantedInterval := 3
err := acc.GatherError(s.Gather)
if err != nil {
t.Fatal(err)
}
time.Sleep(time.Duration(wantedInterval) * time.Second)
err = acc.GatherError(s.Gather)
if err != nil {
t.Fatal(err)
}
if s.interval != wantedInterval {
t.Errorf("wrong interval: got %d, want %d", s.interval, wantedInterval)
}
}