-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmarks_test.go
52 lines (42 loc) · 1.01 KB
/
benchmarks_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
package rivers_test
import (
"errors"
"github.com/drborges/rivers"
"github.com/drborges/rivers/stream"
. "github.com/smartystreets/goconvey/convey"
"math/rand"
"runtime"
"testing"
"time"
)
func slowProcess(data stream.T) {
time.Sleep(time.Second)
}
func BenchmarkParallel(b *testing.B) {
b.ResetTimer()
runtime.GOMAXPROCS(runtime.NumCPU())
numbers := rivers.FromRange(1, 10000).Parallel()
for i := 0; i < b.N; i++ {
numbers = numbers.Each(slowProcess)
}
numbers.Drain()
}
func TestErrorInjection(t *testing.T) {
err := errors.New("Error Injected")
injectError := func(data stream.T) stream.T {
panicFactor := rand.Intn(10)
if panicFactor%2 == 0 {
time.Sleep(500 * time.Millisecond)
panic(err)
} else {
time.Sleep(100 * time.Millisecond)
}
return data
}
Convey("From Range -> Group By", t, func() {
runtime.GOMAXPROCS(runtime.NumCPU())
items, err := rivers.FromRange(1, 1000).Parallel().Map(injectError).Collect()
So(items, ShouldNotBeEmpty)
So(err, ShouldEqual, err)
})
}