-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_test.go
60 lines (52 loc) · 827 Bytes
/
async_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
package async
import (
"errors"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParallel(t *testing.T) {
// Test no errors.
x := 0
m := sync.Mutex{}
ee := Parallel(
func() error {
m.Lock()
defer m.Unlock()
x++
return nil
},
func() error {
m.Lock()
defer m.Unlock()
x += 2
return nil
},
func() error {
m.Lock()
defer m.Unlock()
x += 3
return nil
},
)
assert.True(t, ee.IsEmpty())
assert.Equal(t, 6, x)
// Test witb errors.
y := 0
ee = Parallel(
func() error {
return errors.New("error 1")
},
func() error {
return errors.New("error 2")
},
func() error {
y--
return errors.New("error 3")
},
)
assert.False(t, ee.IsEmpty())
assert.Equal(t, 3, len(ee.All()))
assert.NotNil(t, ee.ToError())
assert.Equal(t, -1, y)
}