-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_test.go
71 lines (67 loc) · 1.39 KB
/
parallel_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package flash
import (
"context"
"testing"
)
func TestParallel_Execute(t *testing.T) {
type fields struct {
executables []Executable
completion bool
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "success - Work 100 tasks - expect complete",
fields: fields{
executables: nTasks(100),
completion: true,
},
wantErr: false,
},
{
name: "success - work all tasks - expect incomplete",
fields: fields{executables: []Executable{
&testTask{
ID: 1,
Fail: true,
Delay: "2s",
}, &testTask{
ID: 2,
Fail: false,
Delay: "100ms",
},
},
completion: false,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewParallel(context.TODO())
for _, task := range tt.fields.executables {
p.Add(task)
}
if err := p.Execute(); (err != nil) != tt.wantErr {
t.Errorf("Execute() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.fields.completion != p.IsCompleted() {
t.Errorf("Execute() tasks expected to be completed but incomplete %+v", tt.fields.executables)
}
})
}
}
func BenchmarkParallel_Execute(b *testing.B) {
tasks := nTasks(1000)
p := NewParallel(context.TODO())
for _, task := range tasks {
p.Add(task)
}
b.ResetTimer()
if err := p.Execute(); err != nil {
b.Errorf("Execute() error = %v", err)
}
}