-
Notifications
You must be signed in to change notification settings - Fork 2
/
parallel_test.go
70 lines (61 loc) · 1.73 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
package async_test
import (
"fmt"
"github.com/Southern/async"
"testing"
"time"
)
func TestParallel(t *testing.T) {
Status("Calling parallel")
async.Parallel([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg1", "arg2", "arg3")
},
func(done async.Done, args ...interface{}) {
Status("Second parallel function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg4", "arg5", "arg6")
},
func(done async.Done, args ...interface{}) {
Status("Third parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg7", "arg8", "arg9")
},
}, func(err error, results ...interface{}) {
if err != nil {
t.Errorf("Parallel threw an unexpected error: %+v", err)
return
}
Status("Parallel completed with results: %+v", results)
})
}
func TestParallelError(t *testing.T) {
Status("Calling Parallel")
async.Parallel([]async.Routine{
func(done async.Done, args ...interface{}) {
Status("First parallel function")
Status("Called with arguments: %+v", args)
time.Sleep(time.Second)
done(nil, "arg1", "arg2", "arg3")
},
func(done async.Done, args ...interface{}) {
Status("Second parallel function")
Status("Called with arguments: %+v", args)
done(fmt.Errorf("Test error"))
},
func(done async.Done, args ...interface{}) {
Status("Third parallel function")
Status("Called with arguments: %+v", args)
done(nil, "arg4", "arg5", "arg6")
},
}, func(err error, results ...interface{}) {
if err != nil {
Status("Parallel exited with error: %+v", err)
return
}
t.Errorf("Parallel did not throw an error as expected")
})
}