mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
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"
|
|
"go.temporal.io/server/common/debug"
|
|
"go.temporal.io/server/common/log"
|
|
p "go.temporal.io/server/common/persistence"
|
|
"go.temporal.io/server/common/persistence/serialization"
|
|
"go.temporal.io/server/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)
|
|
}
|