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`.
135 lines
3.5 KiB
Go
135 lines
3.5 KiB
Go
package persistence
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
historypb "go.temporal.io/api/history/v1"
|
|
"go.temporal.io/server/common"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/payloads"
|
|
"go.temporal.io/server/common/persistence/serialization"
|
|
"go.temporal.io/server/common/testing/protorequire"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
)
|
|
|
|
type (
|
|
temporalSerializerSuite struct {
|
|
suite.Suite
|
|
// override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
|
|
// not merely log an error
|
|
*require.Assertions
|
|
protorequire.ProtoAssertions
|
|
logger log.Logger
|
|
}
|
|
)
|
|
|
|
func TestTemporalSerializerSuite(t *testing.T) {
|
|
s := new(temporalSerializerSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *temporalSerializerSuite) SetupTest() {
|
|
s.logger = log.NewTestLogger()
|
|
// Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
|
|
s.Assertions = require.New(s.T())
|
|
s.ProtoAssertions = protorequire.New(s.T())
|
|
}
|
|
|
|
func (s *temporalSerializerSuite) TestSerializer() {
|
|
|
|
concurrency := 1
|
|
startWG := sync.WaitGroup{}
|
|
doneWG := sync.WaitGroup{}
|
|
|
|
startWG.Add(1)
|
|
doneWG.Add(concurrency)
|
|
|
|
serializer := serialization.NewSerializer()
|
|
|
|
eventType := enumspb.EVENT_TYPE_ACTIVITY_TASK_COMPLETED
|
|
event0 := &historypb.HistoryEvent{
|
|
EventId: 999,
|
|
EventTime: timestamppb.New(time.Date(2020, 8, 22, 0, 0, 0, 0, time.UTC)),
|
|
EventType: eventType,
|
|
Attributes: &historypb.HistoryEvent_ActivityTaskCompletedEventAttributes{
|
|
ActivityTaskCompletedEventAttributes: &historypb.ActivityTaskCompletedEventAttributes{
|
|
Result: payloads.EncodeString("result-1-event-1"),
|
|
ScheduledEventId: 4,
|
|
StartedEventId: 5,
|
|
Identity: "event-1",
|
|
},
|
|
},
|
|
}
|
|
|
|
history0 := &historypb.History{Events: []*historypb.HistoryEvent{event0, event0}}
|
|
|
|
for i := 0; i < concurrency; i++ {
|
|
|
|
go func() {
|
|
|
|
startWG.Wait()
|
|
defer doneWG.Done()
|
|
|
|
// serialize event
|
|
|
|
nilEvent, err := serializer.SerializeEvent(nil, enumspb.ENCODING_TYPE_PROTO3)
|
|
s.Nil(err)
|
|
s.Nil(nilEvent)
|
|
|
|
_, err = serializer.SerializeEvent(event0, enumspb.ENCODING_TYPE_UNSPECIFIED)
|
|
s.NotNil(err)
|
|
_, ok := err.(*serialization.UnknownEncodingTypeError)
|
|
s.True(ok)
|
|
|
|
dProto, err := serializer.SerializeEvent(event0, enumspb.ENCODING_TYPE_PROTO3)
|
|
s.Nil(err)
|
|
s.NotNil(dProto)
|
|
|
|
// serialize batch events
|
|
|
|
nilEvents, err := serializer.SerializeEvents(nil, enumspb.ENCODING_TYPE_PROTO3)
|
|
s.Nil(err)
|
|
s.NotNil(nilEvents)
|
|
|
|
_, err = serializer.SerializeEvents(history0.Events, enumspb.ENCODING_TYPE_UNSPECIFIED)
|
|
s.NotNil(err)
|
|
_, ok = err.(*serialization.UnknownEncodingTypeError)
|
|
s.True(ok)
|
|
|
|
dsProto, err := serializer.SerializeEvents(history0.Events, enumspb.ENCODING_TYPE_PROTO3)
|
|
s.Nil(err)
|
|
s.NotNil(dsProto)
|
|
|
|
// deserialize event
|
|
|
|
dNilEvent, err := serializer.DeserializeEvent(nilEvent)
|
|
s.Nil(err)
|
|
s.Nil(dNilEvent)
|
|
|
|
event2, err := serializer.DeserializeEvent(dProto)
|
|
s.Nil(err)
|
|
s.ProtoEqual(event0, event2)
|
|
|
|
// deserialize events
|
|
|
|
dNilEvents, err := serializer.DeserializeEvents(nilEvents)
|
|
s.Nil(err)
|
|
s.Nil(dNilEvents)
|
|
|
|
events, err := serializer.DeserializeEvents(dsProto)
|
|
history2 := &historypb.History{Events: events}
|
|
s.Nil(err)
|
|
s.ProtoEqual(history0, history2)
|
|
}()
|
|
}
|
|
|
|
startWG.Done()
|
|
succ := common.AwaitWaitGroup(&doneWG, 10*time.Second)
|
|
s.True(succ, "test timed out")
|
|
}
|