clean up tests

This commit is contained in:
Steven Soroka 2020-06-26 17:29:39 -04:00
parent 9785d3c2c6
commit 5c8666d1af
3 changed files with 3 additions and 18 deletions

View File

@ -235,10 +235,6 @@ func testRFC5426(t *testing.T, protocol string, address string, bestEffort bool)
require.NoError(t, receiver.Start(acc)) require.NoError(t, receiver.Start(acc))
defer receiver.Stop() defer receiver.Stop()
// Clear
acc.ClearMetrics()
acc.Errors = make([]error, 0)
// Connect // Connect
conn, err := net.Dial(protocol, address) conn, err := net.Dial(protocol, address)
require.NotNil(t, conn) require.NotNil(t, conn)

View File

@ -51,10 +51,11 @@ func TestExternalProcessorWorks(t *testing.T) {
} }
acc.Wait(1) acc.Wait(1)
m := acc.GetTelegrafMetrics()[0]
require.NoError(t, e.Stop()) require.NoError(t, e.Stop())
metrics = acc.GetTelegrafMetrics()
m := metrics[0]
expected := testutil.MustMetric("test", expected := testutil.MustMetric("test",
map[string]string{ map[string]string{
"city": "Toronto", "city": "Toronto",
@ -70,8 +71,6 @@ func TestExternalProcessorWorks(t *testing.T) {
metricTime := m.Time().UnixNano() metricTime := m.Time().UnixNano()
// read the other 9 and make sure they're ordered properly // read the other 9 and make sure they're ordered properly
acc.Wait(9)
metrics = acc.GetTelegrafMetrics()
for i := 0; i < 9; i++ { for i := 0; i < 9; i++ {
m = metrics[i+1] m = metrics[i+1]
require.EqualValues(t, metricTime+1, m.Time().UnixNano()) require.EqualValues(t, metricTime+1, m.Time().UnixNano())

View File

@ -55,8 +55,6 @@ func (a *Accumulator) NMetrics() uint64 {
} }
func (a *Accumulator) GetTelegrafMetrics() []telegraf.Metric { func (a *Accumulator) GetTelegrafMetrics() []telegraf.Metric {
a.Lock()
defer a.Unlock()
metrics := []telegraf.Metric{} metrics := []telegraf.Metric{}
for _, m := range a.Metrics { for _, m := range a.Metrics {
metrics = append(metrics, FromTestMetric(m)) metrics = append(metrics, FromTestMetric(m))
@ -253,8 +251,6 @@ func (a *Accumulator) SetDebug(debug bool) {
// Get gets the specified measurement point from the accumulator // Get gets the specified measurement point from the accumulator
func (a *Accumulator) Get(measurement string) (*Metric, bool) { func (a *Accumulator) Get(measurement string) (*Metric, bool) {
a.Lock()
defer a.Unlock()
for _, p := range a.Metrics { for _, p := range a.Metrics {
if p.Measurement == measurement { if p.Measurement == measurement {
return p, true return p, true
@ -265,8 +261,6 @@ func (a *Accumulator) Get(measurement string) (*Metric, bool) {
} }
func (a *Accumulator) HasTag(measurement string, key string) bool { func (a *Accumulator) HasTag(measurement string, key string) bool {
a.Lock()
defer a.Unlock()
for _, p := range a.Metrics { for _, p := range a.Metrics {
if p.Measurement == measurement { if p.Measurement == measurement {
_, ok := p.Tags[key] _, ok := p.Tags[key]
@ -277,8 +271,6 @@ func (a *Accumulator) HasTag(measurement string, key string) bool {
} }
func (a *Accumulator) TagSetValue(measurement string, key string) string { func (a *Accumulator) TagSetValue(measurement string, key string) string {
a.Lock()
defer a.Unlock()
for _, p := range a.Metrics { for _, p := range a.Metrics {
if p.Measurement == measurement { if p.Measurement == measurement {
v, ok := p.Tags[key] v, ok := p.Tags[key]
@ -291,8 +283,6 @@ func (a *Accumulator) TagSetValue(measurement string, key string) string {
} }
func (a *Accumulator) TagValue(measurement string, key string) string { func (a *Accumulator) TagValue(measurement string, key string) string {
a.Lock()
defer a.Unlock()
for _, p := range a.Metrics { for _, p := range a.Metrics {
if p.Measurement == measurement { if p.Measurement == measurement {
v, ok := p.Tags[key] v, ok := p.Tags[key]