From 6cd736aba000172776d5e77eb58f4aba78052dd8 Mon Sep 17 00:00:00 2001 From: Rene Zbinden Date: Sat, 2 Apr 2016 10:15:14 +0200 Subject: [PATCH] disable TestInterval with -race test option --- .../inputs/sysstat/sysstat_interval_test.go | 40 +++++++++++++++++++ plugins/inputs/sysstat/sysstat_test.go | 28 ------------- 2 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 plugins/inputs/sysstat/sysstat_interval_test.go diff --git a/plugins/inputs/sysstat/sysstat_interval_test.go b/plugins/inputs/sysstat/sysstat_interval_test.go new file mode 100644 index 000000000..3d92f6873 --- /dev/null +++ b/plugins/inputs/sysstat/sysstat_interval_test.go @@ -0,0 +1,40 @@ +// +build +linux !race + +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) { + // overwriting exec commands with mock commands + execCommand = fakeExecCommand + defer func() { execCommand = exec.Command }() + var acc testutil.Accumulator + + s.interval = 0 + wantedInterval := 3 + + err := s.Gather(&acc) + if err != nil { + t.Fatal(err) + } + + time.Sleep(time.Duration(wantedInterval) * time.Second) + + err = s.Gather(&acc) + if err != nil { + t.Fatal(err) + } + + if s.interval != wantedInterval { + t.Errorf("wrong interval: got %d, want %d", s.interval, wantedInterval) + } +} diff --git a/plugins/inputs/sysstat/sysstat_test.go b/plugins/inputs/sysstat/sysstat_test.go index d55ca9dbf..57f97a64f 100644 --- a/plugins/inputs/sysstat/sysstat_test.go +++ b/plugins/inputs/sysstat/sysstat_test.go @@ -8,7 +8,6 @@ import ( "os/exec" "path" "testing" - "time" "github.com/influxdata/telegraf/testutil" ) @@ -304,30 +303,3 @@ dell-xps 5 2016-03-25 16:18:10 UTC sdb %util 0.30 // some code here to check arguments perhaps? os.Exit(0) } - -// TestGatherInterval checks that interval is correctly set. -func TestGatherInterval(t *testing.T) { - // overwriting exec commands with mock commands - execCommand = fakeExecCommand - defer func() { execCommand = exec.Command }() - var acc testutil.Accumulator - - s.interval = 0 - wantedInterval := 3 - - err := s.Gather(&acc) - if err != nil { - t.Fatal(err) - } - - time.Sleep(time.Duration(wantedInterval) * time.Second) - - err = s.Gather(&acc) - if err != nil { - t.Fatal(err) - } - - if s.interval != wantedInterval { - t.Errorf("wrong interval: got %d, want %d", s.interval, wantedInterval) - } -}