Skip to content

Commit

Permalink
test(engine): put DelaySeq under test
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Sep 27, 2024
1 parent d14ae3b commit 7eaf42d
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion engine/promise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestPromise_Force(t *testing.T) {
func TestPromise_ForceWithDelayedExecutions(t *testing.T) {
var res []int
k := Delay(func(context.Context) *Promise {
res = append(res, 1)
Expand Down Expand Up @@ -73,3 +73,42 @@ func TestPromise_Force(t *testing.T) {
assert.Equal(t, 10, count)
})
}

func TestPromise_ForceWithDelayedSequenceExecutions(t *testing.T) {
var res []int
k := DelaySeq(
func() NextFunc {
i := 0
return func() (PromiseFunc, bool) {
defer func() { i++ }()

v := i
res = append(res, v)
return func(ctx context.Context) *Promise {
return Bool(v%((v%4)+1) == 0)
}, i < 11
}
}())

t.Run("ok", func(t *testing.T) {
cases := []struct {
wantOk bool
wantRes []int
}{
{wantOk: true, wantRes: []int{0}},
{wantOk: true, wantRes: []int{1, 2, 3, 4}},
{wantOk: true, wantRes: []int{5, 6}},
{wantOk: true, wantRes: []int{7, 8}},
{wantOk: false, wantRes: []int{9, 10, 11}},
{wantOk: false, wantRes: nil},
}

for _, tc := range cases {
res = nil
ok, err := k.Force(context.Background())
assert.NoError(t, err)
assert.Equal(t, tc.wantOk, ok)
assert.Equal(t, tc.wantRes, res)
}
})
}

0 comments on commit 7eaf42d

Please sign in to comment.