From 180eb2cebb4c90d72ba687c16b13d5c30c01976e Mon Sep 17 00:00:00 2001 From: Steven Soroka Date: Fri, 9 Oct 2020 16:10:17 -0400 Subject: [PATCH] fix flakey tests --- plugins/inputs/processes/processes_test.go | 67 +++---------------- .../inputs/tcp_listener/tcp_listener_test.go | 3 +- testutil/accumulator.go | 10 ++- 3 files changed, 19 insertions(+), 61 deletions(-) diff --git a/plugins/inputs/processes/processes_test.go b/plugins/inputs/processes/processes_test.go index 762d1b50f9aba..ca74bd0f59442 100644 --- a/plugins/inputs/processes/processes_test.go +++ b/plugins/inputs/processes/processes_test.go @@ -38,7 +38,7 @@ func TestProcesses(t *testing.T) { func TestFromPS(t *testing.T) { processes := &Processes{ Log: testutil.Logger{}, - execPS: testExecPS, + execPS: testExecPS("\nSTAT\nD\nI\nL\nR\nR+\nS\nS+\nSNs\nSs\nU\nZ\n"), forcePS: true, } @@ -47,12 +47,12 @@ func TestFromPS(t *testing.T) { require.NoError(t, err) fields := getEmptyFields() - fields["blocked"] = int64(4) + fields["blocked"] = int64(3) fields["zombies"] = int64(1) - fields["running"] = int64(4) - fields["sleeping"] = int64(34) - fields["idle"] = int64(2) - fields["total"] = int64(45) + fields["running"] = int64(2) + fields["sleeping"] = int64(4) + fields["idle"] = int64(1) + fields["total"] = int64(11) acc.AssertContainsTaggedFields(t, "processes", fields, map[string]string{}) } @@ -169,8 +169,8 @@ func TestParkedProcess(t *testing.T) { testutil.IgnoreTime()) } -func testExecPS() ([]byte, error) { - return []byte(testPSOut), nil +func testExecPS(out string) func() ([]byte, error) { + return func() ([]byte, error) { return []byte(out), nil } } // struct for counting calls to testProcFile @@ -189,58 +189,9 @@ func (t *tester) testProcFile2(_ string) ([]byte, error) { } func testExecPSError() ([]byte, error) { - return []byte(testPSOut), fmt.Errorf("ERROR!") + return []byte("\nSTAT\nD\nI\nL\nR\nR+\nS\nS+\nSNs\nSs\nU\nZ\n"), fmt.Errorf("ERROR!") } -const testPSOut = ` -STAT -S -S -S -S -R -R -S -S -Ss -Ss -S -SNs -Ss -Ss -S -R+ -S -U -S -S -S -S -Ss -S+ -Ss -S -S+ -S+ -Ss -S+ -Ss -S -R+ -Ss -S -S+ -S+ -Ss -L -U -Z -D -S+ -I -I -` - const testProcStat = `10 (rcuob/0) %s 2 0 0 0 -1 2129984 0 0 0 0 0 0 0 0 20 0 %s 0 11 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 18446744073709551615 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ` diff --git a/plugins/inputs/tcp_listener/tcp_listener_test.go b/plugins/inputs/tcp_listener/tcp_listener_test.go index 16895d6740efe..bb83f0465bd77 100644 --- a/plugins/inputs/tcp_listener/tcp_listener_test.go +++ b/plugins/inputs/tcp_listener/tcp_listener_test.go @@ -264,11 +264,12 @@ func TestRunParserInvalidMsg(t *testing.T) { listener.parser, _ = parsers.NewInfluxParser() listener.wg.Add(1) - go listener.tcpParser() buf := bytes.NewBuffer(nil) log.SetOutput(buf) defer log.SetOutput(os.Stderr) + + go listener.tcpParser() in <- testmsg scnr := bufio.NewScanner(buf) diff --git a/testutil/accumulator.go b/testutil/accumulator.go index 978fb7b38ddf5..6e754da45a220 100644 --- a/testutil/accumulator.go +++ b/testutil/accumulator.go @@ -363,7 +363,13 @@ func (a *Accumulator) AssertContainsTaggedFields( return } } - msg := fmt.Sprintf("unknown measurement %s with tags %v", measurement, tags) + // We've failed. spit out some debug logging + for _, p := range a.Metrics { + if p.Measurement == measurement { + t.Log("measurement", p.Measurement, "tags", p.Tags, "fields", p.Fields) + } + } + msg := fmt.Sprintf("unknown measurement %q with tags %v", measurement, tags) assert.Fail(t, msg) } @@ -403,7 +409,7 @@ func (a *Accumulator) AssertContainsFields( return } } - msg := fmt.Sprintf("unknown measurement %s", measurement) + msg := fmt.Sprintf("unknown measurement %q", measurement) assert.Fail(t, msg) }