mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
108 lines
3.1 KiB
Go
108 lines
3.1 KiB
Go
package batcher
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/mock"
|
|
"github.com/stretchr/testify/suite"
|
|
batchpb "go.temporal.io/api/batch/v1"
|
|
commonpb "go.temporal.io/api/common/v1"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"go.temporal.io/api/workflowservice/v1"
|
|
"go.temporal.io/sdk/testsuite"
|
|
batchspb "github.com/hanzoai/tasks/api/batch/v1"
|
|
"go.uber.org/mock/gomock"
|
|
)
|
|
|
|
type batcherSuite struct {
|
|
suite.Suite
|
|
testsuite.WorkflowTestSuite
|
|
controller *gomock.Controller
|
|
env *testsuite.TestWorkflowEnvironment
|
|
}
|
|
|
|
func TestBatcherSuite(t *testing.T) {
|
|
suite.Run(t, new(batcherSuite))
|
|
}
|
|
|
|
func (s *batcherSuite) SetupTest() {
|
|
s.controller = gomock.NewController(s.T())
|
|
s.env = s.WorkflowTestSuite.NewTestWorkflowEnvironment()
|
|
s.env.RegisterWorkflow(BatchWorkflowProtobuf)
|
|
}
|
|
|
|
func (s *batcherSuite) TearDownTest() {
|
|
s.controller.Finish()
|
|
s.env.AssertExpectations(s.T())
|
|
}
|
|
|
|
func (s *batcherSuite) TestBatchWorkflow_ValidParams_Query_Protobuf() {
|
|
var ac *activities
|
|
s.env.OnActivity(ac.BatchActivityWithProtobuf, mock.Anything, mock.Anything).Return(HeartBeatDetails{
|
|
SuccessCount: 42,
|
|
ErrorCount: 27,
|
|
}, nil)
|
|
s.env.OnUpsertMemo(mock.Anything).Run(func(args mock.Arguments) {
|
|
memo, ok := args.Get(0).(map[string]any)
|
|
s.Require().True(ok)
|
|
s.Equal(map[string]any{
|
|
"batch_operation_stats": BatchOperationStats{
|
|
NumSuccess: 42,
|
|
NumFailure: 27,
|
|
},
|
|
}, memo)
|
|
}).Once()
|
|
s.env.ExecuteWorkflow(BatchWorkflowProtobuf, &batchspb.BatchOperationInput{
|
|
Request: &workflowservice.StartBatchOperationRequest{
|
|
JobId: uuid.NewString(),
|
|
Operation: &workflowservice.StartBatchOperationRequest_TerminationOperation{
|
|
TerminationOperation: &batchpb.BatchOperationTermination{},
|
|
},
|
|
Namespace: "test-namespace",
|
|
Reason: "test-reason",
|
|
VisibilityQuery: "test-query",
|
|
},
|
|
BatchType: enumspb.BATCH_OPERATION_TYPE_TERMINATE,
|
|
})
|
|
err := s.env.GetWorkflowError()
|
|
s.Require().NoError(err)
|
|
}
|
|
|
|
func (s *batcherSuite) TestBatchWorkflow_ValidParams_Executions_Protobuf() {
|
|
var ac *activities
|
|
s.env.OnActivity(ac.BatchActivityWithProtobuf, mock.Anything, mock.Anything).Return(HeartBeatDetails{
|
|
SuccessCount: 42,
|
|
ErrorCount: 27,
|
|
}, nil)
|
|
s.env.OnUpsertMemo(mock.Anything).Run(func(args mock.Arguments) {
|
|
memo, ok := args.Get(0).(map[string]any)
|
|
s.Require().True(ok)
|
|
s.Equal(map[string]any{
|
|
"batch_operation_stats": BatchOperationStats{
|
|
NumSuccess: 42,
|
|
NumFailure: 27,
|
|
},
|
|
}, memo)
|
|
}).Once()
|
|
s.env.ExecuteWorkflow(BatchWorkflowProtobuf, &batchspb.BatchOperationInput{
|
|
Request: &workflowservice.StartBatchOperationRequest{
|
|
JobId: uuid.NewString(),
|
|
Operation: &workflowservice.StartBatchOperationRequest_TerminationOperation{
|
|
TerminationOperation: &batchpb.BatchOperationTermination{},
|
|
},
|
|
Executions: []*commonpb.WorkflowExecution{
|
|
{
|
|
WorkflowId: uuid.NewString(),
|
|
RunId: uuid.NewString(),
|
|
},
|
|
},
|
|
Reason: "test-reason",
|
|
Namespace: "test-namespace",
|
|
},
|
|
BatchType: enumspb.BATCH_OPERATION_TYPE_TERMINATE,
|
|
})
|
|
err := s.env.GetWorkflowError()
|
|
s.Require().NoError(err)
|
|
}
|