-
Notifications
You must be signed in to change notification settings - Fork 202
/
retry_activity_workflow_test.go
46 lines (39 loc) · 1.2 KB
/
retry_activity_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
package retryactivity
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"go.temporal.io/sdk/activity"
"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() {
env := s.NewTestWorkflowEnvironment()
env.RegisterActivity(BatchProcessingActivity)
var startedIDs []int
env.OnActivity(BatchProcessingActivity, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(func(ctx context.Context, firstTaskID, batchSize int, processDelay time.Duration) error {
i := firstTaskID
if activity.HasHeartbeatDetails(ctx) {
var completedIdx int
if err := activity.GetHeartbeatDetails(ctx, &completedIdx); err == nil {
i = completedIdx + 1
}
}
startedIDs = append(startedIDs, i)
return BatchProcessingActivity(ctx, firstTaskID, batchSize, time.Nanosecond /* override for test */)
})
env.ExecuteWorkflow(RetryWorkflow)
s.True(env.IsWorkflowCompleted())
s.NoError(env.GetWorkflowError())
s.Equal([]int{0, 6, 12, 18}, startedIDs)
env.AssertExpectations(s.T())
}