diff --git a/internal/models/running_aggregator_test.go b/internal/models/running_aggregator_test.go index 83b9dea0a..a85885965 100644 --- a/internal/models/running_aggregator_test.go +++ b/internal/models/running_aggregator_test.go @@ -1,7 +1,6 @@ package models import ( - "sync/atomic" "testing" "time" @@ -246,7 +245,7 @@ type TestAggregator struct { func (t *TestAggregator) Description() string { return "" } func (t *TestAggregator) SampleConfig() string { return "" } func (t *TestAggregator) Reset() { - atomic.StoreInt64(&t.sum, 0) + t.sum = 0 } func (t *TestAggregator) Push(acc telegraf.Accumulator) { @@ -259,7 +258,7 @@ func (t *TestAggregator) Push(acc telegraf.Accumulator) { func (t *TestAggregator) Add(in telegraf.Metric) { for _, v := range in.Fields() { if vi, ok := v.(int64); ok { - atomic.AddInt64(&t.sum, vi) + t.sum += vi } } } diff --git a/plugins/inputs/vsphere/vsphere_test.go b/plugins/inputs/vsphere/vsphere_test.go index b66fa45eb..dce21fa78 100644 --- a/plugins/inputs/vsphere/vsphere_test.go +++ b/plugins/inputs/vsphere/vsphere_test.go @@ -5,9 +5,6 @@ import ( "crypto/tls" "fmt" "regexp" - "sort" - "sync" - "sync/atomic" "testing" "time" "unsafe" @@ -230,36 +227,6 @@ func TestParseConfig(t *testing.T) { require.NotNil(t, tab) } -func TestThrottledExecutor(t *testing.T) { - max := int64(0) - ngr := int64(0) - n := 10000 - var mux sync.Mutex - results := make([]int, 0, n) - te := NewThrottledExecutor(5) - for i := 0; i < n; i++ { - func(i int) { - te.Run(context.Background(), func() { - atomic.AddInt64(&ngr, 1) - mux.Lock() - defer mux.Unlock() - results = append(results, i*2) - if ngr > max { - max = ngr - } - time.Sleep(100 * time.Microsecond) - atomic.AddInt64(&ngr, -1) - }) - }(i) - } - te.Wait() - sort.Ints(results) - for i := 0; i < n; i++ { - require.Equal(t, results[i], i*2, "Some jobs didn't run") - } - require.Equal(t, int64(5), max, "Wrong number of goroutines spawned") -} - func TestMaxQuery(t *testing.T) { // Don't run test on 32-bit machines due to bug in simulator. // https://github.com/vmware/govmomi/issues/1330 diff --git a/testutil/accumulator.go b/testutil/accumulator.go index 65592b5a0..5716d3518 100644 --- a/testutil/accumulator.go +++ b/testutil/accumulator.go @@ -18,8 +18,8 @@ var ( ) func newTrackingID() telegraf.TrackingID { - atomic.AddUint64(&lastID, 1) - return telegraf.TrackingID(lastID) + id := atomic.AddUint64(&lastID, 1) + return telegraf.TrackingID(id) } // Metric defines a single point measurement