Files
tasks/common/persistence/history_manager_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

137 lines
4.2 KiB
Go

package persistence_test
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"go.temporal.io/api/serviceerror"
"github.com/hanzoai/tasks/common/dynamicconfig"
"github.com/hanzoai/tasks/common/log"
p "github.com/hanzoai/tasks/common/persistence"
"github.com/hanzoai/tasks/common/persistence/mock"
"github.com/hanzoai/tasks/common/persistence/serialization"
"go.uber.org/mock/gomock"
)
func TestHistoryManager_InvalidBranchToken_ReturnsInvalidArgument(t *testing.T) {
// Invalid protobuf bytes that will fail to parse
invalidBranchToken := []byte{0xFF, 0xFF, 0xFF, 0xFF}
tests := []struct {
name string
testFunc func(t *testing.T, em p.ExecutionManager, invalidToken []byte)
}{
{
name: "ReadHistoryBranch",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
_, err := em.ReadHistoryBranch(context.Background(), &p.ReadHistoryBranchRequest{
ShardID: 1,
BranchToken: invalidToken,
MinEventID: 1,
MaxEventID: 100,
PageSize: 100,
})
requireInvalidArgumentError(t, err, "ReadHistoryBranch")
},
},
{
name: "ReadHistoryBranchByBatch",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
_, err := em.ReadHistoryBranchByBatch(context.Background(), &p.ReadHistoryBranchRequest{
ShardID: 1,
BranchToken: invalidToken,
MinEventID: 1,
MaxEventID: 100,
PageSize: 100,
})
requireInvalidArgumentError(t, err, "ReadHistoryBranchByBatch")
},
},
{
name: "ReadHistoryBranchReverse",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
_, err := em.ReadHistoryBranchReverse(context.Background(), &p.ReadHistoryBranchReverseRequest{
ShardID: 1,
BranchToken: invalidToken,
MaxEventID: 100,
PageSize: 100,
})
requireInvalidArgumentError(t, err, "ReadHistoryBranchReverse")
},
},
{
name: "ReadRawHistoryBranch",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
_, err := em.ReadRawHistoryBranch(context.Background(), &p.ReadHistoryBranchRequest{
ShardID: 1,
BranchToken: invalidToken,
MinEventID: 1,
MaxEventID: 100,
PageSize: 100,
})
requireInvalidArgumentError(t, err, "ReadRawHistoryBranch")
},
},
{
name: "ForkHistoryBranch",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
_, err := em.ForkHistoryBranch(context.Background(), &p.ForkHistoryBranchRequest{
ForkBranchToken: invalidToken,
ForkNodeID: 2,
Info: "test",
ShardID: 1,
NamespaceID: "test-namespace",
NewRunID: "test-run-id",
})
requireInvalidArgumentError(t, err, "ForkHistoryBranch")
},
},
{
name: "DeleteHistoryBranch",
testFunc: func(t *testing.T, em p.ExecutionManager, invalidToken []byte) {
err := em.DeleteHistoryBranch(context.Background(), &p.DeleteHistoryBranchRequest{
ShardID: 1,
BranchToken: invalidToken,
})
requireInvalidArgumentError(t, err, "DeleteHistoryBranch")
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
store := mock.NewMockExecutionStore(ctrl)
// Return a real HistoryBranchUtil that will parse the branch token
store.EXPECT().GetHistoryBranchUtil().AnyTimes().Return(p.NewHistoryBranchUtil(serialization.NewSerializer()))
em := p.NewExecutionManager(
store,
serialization.NewSerializer(),
nil,
log.NewNoopLogger(),
dynamicconfig.GetIntPropertyFn(1024*1024),
dynamicconfig.GetBoolPropertyFn(false),
)
tc.testFunc(t, em, invalidBranchToken)
})
}
}
func requireInvalidArgumentError(t *testing.T, err error, operation string) {
t.Helper()
require.Error(t, err, "%s should return an error for invalid branch token", operation)
var invalidArgErr *serviceerror.InvalidArgument
require.ErrorAs(t, err, &invalidArgErr,
"%s should return InvalidArgument error for invalid branch token, got: %T - %v",
operation, err, err)
require.Contains(t, err.Error(), "unable to parse branch token",
"%s error message should contain 'unable to parse branch token'", operation)
}