Fix race condition in logparser tests (#6825)
This commit is contained in:
parent
a5ef34f6e2
commit
25e1636775
|
@ -6,10 +6,12 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStartNoParsers(t *testing.T) {
|
||||
|
@ -56,32 +58,56 @@ func TestGrokParseLogFiles(t *testing.T) {
|
|||
}
|
||||
|
||||
acc := testutil.Accumulator{}
|
||||
assert.NoError(t, logparser.Start(&acc))
|
||||
acc.Wait(2)
|
||||
require.NoError(t, logparser.Start(&acc))
|
||||
acc.Wait(3)
|
||||
|
||||
logparser.Stop()
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "logparser_grok",
|
||||
expected := []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"logparser_grok",
|
||||
map[string]string{
|
||||
"response_code": "200",
|
||||
"path": thisdir + "testdata/test_a.log",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"clientip": "192.168.1.1",
|
||||
"myfloat": float64(1.25),
|
||||
"response_time": int64(5432),
|
||||
"myint": int64(101),
|
||||
},
|
||||
time.Unix(0, 0),
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"logparser_grok",
|
||||
map[string]string{
|
||||
"response_code": "200",
|
||||
"path": thisdir + "testdata/test_a.log",
|
||||
})
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "logparser_grok",
|
||||
"path": thisdir + "testdata/test_b.log",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"myfloat": 1.25,
|
||||
"mystring": "mystring",
|
||||
"nomodifier": "nomodifier",
|
||||
},
|
||||
time.Unix(0, 0),
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"logparser_grok",
|
||||
map[string]string{
|
||||
"path": thisdir + "testdata/test_b.log",
|
||||
})
|
||||
"path": thisdir + "testdata/test_c.log",
|
||||
"response_code": "200",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"clientip": "192.168.1.1",
|
||||
"myfloat": 1.25,
|
||||
"myint": 101,
|
||||
"response_time": 5432,
|
||||
},
|
||||
time.Unix(0, 0),
|
||||
),
|
||||
}
|
||||
|
||||
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(),
|
||||
testutil.IgnoreTime(), testutil.SortMetrics())
|
||||
}
|
||||
|
||||
func TestGrokParseLogFilesAppearLater(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue