-
Notifications
You must be signed in to change notification settings - Fork 202
/
workflow_test.go
59 lines (47 loc) · 1.49 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
49
50
51
52
53
54
55
56
57
58
59
package timer
import (
"context"
"sync"
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"go.temporal.io/sdk/testsuite"
)
type UnitTestSuite struct {
suite.Suite
testsuite.WorkflowTestSuite
}
func TestUnitTestSuite(t *testing.T) {
suite.Run(t, new(UnitTestSuite))
}
func (s *UnitTestSuite) Test_Workflow_FastProcessing() {
env := s.NewTestWorkflowEnvironment()
// mock to return immediately to simulate fast processing case
env.OnActivity(OrderProcessingActivity, mock.Anything).Return(nil)
env.OnActivity(SendEmailActivity, mock.Anything).Return(func(ctx context.Context) error {
// in fast processing case, this method should not get called
s.FailNow("SendEmailActivity should not get called")
return nil
})
env.ExecuteWorkflow(SampleTimerWorkflow, time.Minute)
s.True(env.IsWorkflowCompleted())
s.NoError(env.GetWorkflowError())
}
func (s *UnitTestSuite) Test_Workflow_SlowProcessing() {
env := s.NewTestWorkflowEnvironment()
wg := &sync.WaitGroup{}
wg.Add(1)
env.OnActivity(OrderProcessingActivity, mock.Anything).Return(func(ctx context.Context) error {
// simulate slow processing, will complete this activity only after the SendEmailActivity is called.
wg.Wait()
return nil
})
env.OnActivity(SendEmailActivity, mock.Anything).Return(func(ctx context.Context) error {
wg.Done()
return nil
})
env.ExecuteWorkflow(SampleTimerWorkflow, time.Microsecond)
s.True(env.IsWorkflowCompleted())
s.NoError(env.GetWorkflowError())
}