fix flakey tests
This commit is contained in:
parent
a8810b2b7a
commit
827b2d4df5
|
|
@ -16,8 +16,8 @@ import (
|
|||
|
||||
func TestProcesses(t *testing.T) {
|
||||
processes := &Processes{
|
||||
Log: testutil.Logger{},
|
||||
execPS: execPS,
|
||||
Log: testutil.Logger{},
|
||||
execPS: testExecPS("STAT\n Ss \n S \n Z \n R \n S< \n SNs \n Ss+ \n \n \n"),
|
||||
readProcFile: readProcFile,
|
||||
}
|
||||
var acc testutil.Accumulator
|
||||
|
|
@ -37,7 +37,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,
|
||||
}
|
||||
|
||||
|
|
@ -46,12 +46,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{})
|
||||
}
|
||||
|
|
@ -168,8 +168,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
|
||||
|
|
@ -188,58 +188,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
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue