-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelpers_test.go
53 lines (46 loc) · 1.03 KB
/
helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package goavro_test
import (
"runtime"
"strings"
"sync"
"testing"
)
func benchmarkLowAndHigh(b *testing.B, callback func()) {
// Run test case in parallel at relative low concurrency
b.Run("Low", func(b *testing.B) {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
callback()
}
})
})
// Run test case in parallel at relative high concurrency
b.Run("High", func(b *testing.B) {
concurrency := runtime.NumCPU() * 1000
wg := new(sync.WaitGroup)
wg.Add(concurrency)
b.ResetTimer()
for c := 0; c < concurrency; c++ {
go func() {
defer wg.Done()
for n := 0; n < b.N; n++ {
callback()
}
}()
}
wg.Wait()
})
}
// ensure code under test returns error containing specified string
func ensureError(tb testing.TB, err error, contains ...string) {
if err == nil {
tb.Errorf("Actual: %v; Expected: %#v", err, contains)
return
}
for _, stub := range contains {
if !strings.Contains(err.Error(), stub) {
tb.Errorf("Actual: %v; Expected: %#v", err, contains)
}
}
}