2016-04-02 08:40:20 +00:00
|
|
|
// +build !race
|
|
|
|
// +build linux
|
2016-04-02 08:15:14 +00:00
|
|
|
|
|
|
|
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) {
|
2017-04-21 17:55:54 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("Skipping test with sleep in short mode.")
|
|
|
|
}
|
2016-04-02 08:15:14 +00:00
|
|
|
// overwriting exec commands with mock commands
|
|
|
|
execCommand = fakeExecCommand
|
|
|
|
defer func() { execCommand = exec.Command }()
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
s.interval = 0
|
|
|
|
wantedInterval := 3
|
|
|
|
|
2017-04-24 18:13:26 +00:00
|
|
|
err := acc.GatherError(s.Gather)
|
2016-04-02 08:15:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(wantedInterval) * time.Second)
|
|
|
|
|
2017-04-24 18:13:26 +00:00
|
|
|
err = acc.GatherError(s.Gather)
|
2016-04-02 08:15:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.interval != wantedInterval {
|
|
|
|
t.Errorf("wrong interval: got %d, want %d", s.interval, wantedInterval)
|
|
|
|
}
|
|
|
|
}
|