-
Notifications
You must be signed in to change notification settings - Fork 202
/
workflow_test.go
42 lines (35 loc) · 1.11 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
package reqrespquery_test
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/temporalio/samples-go/reqrespquery"
"go.temporal.io/sdk/testsuite"
)
func TestUppercaseWorkflow(t *testing.T) {
// Create env
var suite testsuite.WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
env.RegisterWorkflow(reqrespquery.UppercaseWorkflow)
env.RegisterActivity(reqrespquery.UppercaseActivity)
// Add a delayed callback to send a signal
env.RegisterDelayedCallback(func() {
env.SignalWorkflow("request", &reqrespquery.Request{ID: "request1", Input: "foo"})
}, 1)
// Add a delayed callback after that to query
var queryResponse *reqrespquery.Response
var queryErr error
env.RegisterDelayedCallback(func() {
val, err := env.QueryWorkflow("response", "request1")
if err != nil {
queryErr = err
} else {
queryErr = val.Get(&queryResponse)
}
}, 100*time.Millisecond)
// Run workflow
env.ExecuteWorkflow(reqrespquery.UppercaseWorkflow)
// Confirm query response
require.NoError(t, queryErr)
require.Equal(t, &reqrespquery.Response{ID: "request1", Output: "FOO"}, queryResponse)
}