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).
153 lines
3.7 KiB
Go
153 lines
3.7 KiB
Go
package tests
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/hanzoai/tasks/common/debug"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
p "github.com/hanzoai/tasks/common/persistence"
|
|
"github.com/hanzoai/tasks/common/persistence/serialization"
|
|
"github.com/hanzoai/tasks/common/testing/protorequire"
|
|
)
|
|
|
|
type (
|
|
ShardSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
protorequire.ProtoAssertions
|
|
|
|
ShardID int32
|
|
|
|
ShardManager p.ShardManager
|
|
Logger log.Logger
|
|
|
|
Ctx context.Context
|
|
Cancel context.CancelFunc
|
|
}
|
|
)
|
|
|
|
func NewShardSuite(
|
|
t *testing.T,
|
|
shardStore p.ShardStore,
|
|
serializer serialization.Serializer,
|
|
logger log.Logger,
|
|
) *ShardSuite {
|
|
return &ShardSuite{
|
|
Assertions: require.New(t),
|
|
ProtoAssertions: protorequire.New(t),
|
|
ShardManager: p.NewShardManager(
|
|
shardStore,
|
|
serializer,
|
|
),
|
|
Logger: logger,
|
|
}
|
|
}
|
|
|
|
func (s *ShardSuite) SetupSuite() {
|
|
}
|
|
|
|
func (s *ShardSuite) TearDownSuite() {
|
|
}
|
|
|
|
func (s *ShardSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
s.ProtoAssertions = protorequire.New(s.T())
|
|
s.Ctx, s.Cancel = context.WithTimeout(context.Background(), 30*time.Second*debug.TimeoutMultiplier)
|
|
|
|
s.ShardID++
|
|
}
|
|
|
|
func (s *ShardSuite) TearDownTest() {
|
|
s.Cancel()
|
|
}
|
|
|
|
func (s *ShardSuite) TestGetOrCreateShard_Create() {
|
|
rangeID := rand.Int63()
|
|
shardInfo := RandomShardInfo(s.ShardID, rangeID)
|
|
|
|
resp, err := s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
|
|
}
|
|
|
|
func (s *ShardSuite) TestGetOrCreateShard_Get() {
|
|
rangeID := rand.Int63()
|
|
shardInfo := RandomShardInfo(s.ShardID, rangeID)
|
|
|
|
resp, err := s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
|
|
resp, err = s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: RandomShardInfo(s.ShardID, rand.Int63()),
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
}
|
|
|
|
func (s *ShardSuite) TestUpdateShard_OwnershipLost() {
|
|
rangeID := rand.Int63()
|
|
shardInfo := RandomShardInfo(s.ShardID, rangeID)
|
|
|
|
resp, err := s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
|
|
updateRangeID := rand.Int63()
|
|
updateShardInfo := RandomShardInfo(s.ShardID, rand.Int63())
|
|
err = s.ShardManager.UpdateShard(s.Ctx, &p.UpdateShardRequest{
|
|
ShardInfo: updateShardInfo,
|
|
PreviousRangeID: updateRangeID,
|
|
})
|
|
s.IsType(&p.ShardOwnershipLostError{}, err)
|
|
|
|
resp, err = s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
}
|
|
|
|
func (s *ShardSuite) TestUpdateShard_Success() {
|
|
rangeID := rand.Int63()
|
|
shardInfo := RandomShardInfo(s.ShardID, rangeID)
|
|
|
|
resp, err := s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(shardInfo, resp.ShardInfo)
|
|
|
|
updateShardInfo := RandomShardInfo(s.ShardID, rangeID+1)
|
|
err = s.ShardManager.UpdateShard(s.Ctx, &p.UpdateShardRequest{
|
|
ShardInfo: updateShardInfo,
|
|
PreviousRangeID: rangeID,
|
|
})
|
|
s.NoError(err)
|
|
|
|
resp, err = s.ShardManager.GetOrCreateShard(s.Ctx, &p.GetOrCreateShardRequest{
|
|
ShardID: s.ShardID,
|
|
InitialShardInfo: shardInfo,
|
|
})
|
|
s.NoError(err)
|
|
s.ProtoEqual(updateShardInfo, resp.ShardInfo)
|
|
}
|