Skip to content

Commit

Permalink
fix flakey tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored and reimda committed Oct 16, 2020
1 parent 6303d80 commit 180eb2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 61 deletions.
67 changes: 9 additions & 58 deletions plugins/inputs/processes/processes_test.go
Expand Up @@ -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,
}

Expand All @@ -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{})
}
Expand Down Expand Up @@ -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
Expand All @@ -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
`

Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/tcp_listener/tcp_listener_test.go
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions testutil/accumulator.go
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 180eb2c

Please sign in to comment.