forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow_test.go
48 lines (43 loc) · 1.4 KB
/
workflow_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
package reqrespupdate_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/temporalio/samples-go/reqrespupdate"
"go.temporal.io/sdk/testsuite"
)
func TestUppercaseWorkflow(t *testing.T) {
// Create env
var suite testsuite.WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
env.RegisterWorkflow(reqrespupdate.UppercaseWorkflow)
env.RegisterActivity(reqrespupdate.UppercaseActivity)
// Use delayed callbacks to send enoguh updates to cause a continue as new
for i := 0; i < 550; i++ {
i := i
env.RegisterDelayedCallback(func() {
env.UpdateWorkflow(reqrespupdate.UpdateHandler, fmt.Sprintf("test id %d", i), &testsuite.TestUpdateCallback{
OnAccept: func() {
if i >= 500 {
require.Fail(t, "update should fail since it should be trying to continue-as-new")
}
},
OnReject: func(err error) {
if i < 500 {
require.Fail(t, "this update should not fail")
}
require.Error(t, err)
},
OnComplete: func(response interface{}, err error) {
if i >= 500 {
require.Fail(t, "update should fail since it should be trying to continue-as-new")
}
require.NoError(t, err)
require.Equal(t, reqrespupdate.Response{Output: fmt.Sprintf("FOO %d", i)}, response)
},
}, &reqrespupdate.Request{Input: fmt.Sprintf("foo %d", i)})
}, 1)
}
// Run workflow
env.ExecuteWorkflow(reqrespupdate.UppercaseWorkflow, true)
}