Fix atomic usage in tests (#6964)

This commit is contained in:
Daniel Nelson
2020-01-31 14:14:44 -08:00
committed by GitHub
parent 6cac2fb388
commit 38bc81e746
3 changed files with 4 additions and 38 deletions

View File

@@ -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