Skip to content

Commit

Permalink
Fix race condition in logparser tests (influxdata#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Jan 3, 2020
1 parent a5ef34f commit 25e1636
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions plugins/inputs/logparser/logparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
map[string]interface{}{
"clientip": "192.168.1.1",
"myfloat": float64(1.25),
"response_time": int64(5432),
"myint": int64(101),
},
map[string]string{
"response_code": "200",
"path": thisdir + "testdata/test_a.log",
})
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{
"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_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),
),
}

acc.AssertContainsTaggedFields(t, "logparser_grok",
map[string]interface{}{
"myfloat": 1.25,
"mystring": "mystring",
"nomodifier": "nomodifier",
},
map[string]string{
"path": thisdir + "testdata/test_b.log",
})
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(),
testutil.IgnoreTime(), testutil.SortMetrics())
}

func TestGrokParseLogFilesAppearLater(t *testing.T) {
Expand Down

0 comments on commit 25e1636

Please sign in to comment.