This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flow_test.go
66 lines (46 loc) · 1.43 KB
/
flow_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
package executor
import (
"context"
"math"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestControlFlow(t *testing.T) {
t.Parallel()
parallel := Parallel{}
t.Run("exceed max", func(t *testing.T) {
t.Parallel()
exec := ControlFlow(parallel, int64(runtime.NumCPU()), 2)
noopAct := ActionFunc(func(ctx context.Context) error { return nil })
err := exec.Execute(context.Background(), noopAct, noopAct, noopAct)
assert.Error(t, err)
})
t.Run("deadline on calls", func(t *testing.T) {
t.Parallel()
exec := ControlFlow(parallel, 1, math.MaxInt64)
go exec.Execute(context.Background(), ActionFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
return nil
}))
time.Sleep(time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
err := exec.Execute(ctx, nil)
assert.Equal(t, context.DeadlineExceeded, err)
})
t.Run("deadline on actions", func(t *testing.T) {
t.Parallel()
exec := ControlFlow(parallel, math.MaxInt64, 1)
go exec.Execute(context.Background(), ActionFunc(func(ctx context.Context) error {
time.Sleep(time.Second)
return nil
}))
time.Sleep(time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
err := exec.Execute(ctx, ActionFunc(func(ctx context.Context) error { return nil }))
assert.Equal(t, context.DeadlineExceeded, err)
})
}