Files
tasks/chasm/ref_test.go
jiechenzandGitHub 929412e504 Route delete execution replication task by archetype ID (#9831)
## What changed?
On the passive clusters side, route delete execution replication tasks
based on `archetypeID` from `RawTaskInfo`:
- `WorkflowArchetypeID` or `UnspecifiedArchetypeID` →
`engine.DeleteWorkflowExecution` path
- Any other archetype → `ChasmEngine.DeleteExecution`

## Why?
Today, the sender (`context_impl.go`) only generates
`DeleteExecutionReplicationTask` for `WorkflowArchetypeID`. The receiver
previously dropped all non-workflow archetypes.

This change makes the receiver forward-compatible: when delete
replication is enabled for non-workflow Chasm archetypes (activity,
scheduler, etc.) in the future, the standby side will already handle
them via
`ChasmEngine.DeleteExecution`.

`UnspecifiedArchetypeID` (0) routes to the workflow path for backward
compatibility. Assumption is old senders don't populate `ArchetypeId` in
`RawTaskInfo`, and historically only workflows produced delete
replication tasks. Routing `0` to the Chasm path would fail because
`getExecutionLease` looks up `current_chasm_executions` by archetype ID.

## How did you test it?
- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks

**`deleteChasmExecution` path is untested end-to-end**: The sender guard
in `context_impl.go:1032` prevents non-workflow delete replication tasks
from being generated, so the `ChasmEngine.DeleteExecution` branch cannot
be coverred in integration tests today
2026-04-08 15:50:38 -07:00

117 lines
3.3 KiB
Go

package chasm
import (
"math/rand"
"reflect"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
persistencespb "go.temporal.io/server/api/persistence/v1"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/primitives"
"go.temporal.io/server/common/testing/protorequire"
"go.uber.org/mock/gomock"
)
type componentRefSuite struct {
suite.Suite
*require.Assertions
protorequire.ProtoAssertions
controller *gomock.Controller
registry *Registry
}
func TestComponentRefSuite(t *testing.T) {
suite.Run(t, new(componentRefSuite))
}
func (s *componentRefSuite) SetupTest() {
// Do this in SetupSubTest() as well, if we have sub tests in this suite.
s.Assertions = require.New(s.T())
s.ProtoAssertions = protorequire.New(s.T())
s.controller = gomock.NewController(s.T())
s.registry = NewRegistry(log.NewTestLogger())
err := s.registry.Register(newTestLibrary(s.controller))
s.NoError(err)
}
func (s *componentRefSuite) TestArchetypeID() {
executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
RunID: primitives.NewUUID().String(),
}
ref := NewComponentRef[*TestComponent](executionKey)
archetypeID, err := ref.ArchetypeID(s.registry)
s.NoError(err)
rc, ok := s.registry.componentOf(reflect.TypeFor[*TestComponent]())
s.True(ok)
s.Equal(rc.componentID, archetypeID)
}
func (s *componentRefSuite) TestNewComponentRefByArchetypeID() {
executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
RunID: primitives.NewUUID().String(),
}
expectArchetypeID := WorkflowArchetypeID
ref := NewComponentRefByArchetypeID(executionKey, expectArchetypeID)
s.Equal(executionKey, ref.ExecutionKey)
archetypeID, err := ref.ArchetypeID(s.registry)
s.NoError(err)
s.Equal(expectArchetypeID, archetypeID)
}
func (s *componentRefSuite) TestSerializeDeserialize() {
_, err := DeserializeComponentRef(nil)
s.ErrorIs(err, ErrInvalidComponentRef)
_, err = DeserializeComponentRef([]byte{})
s.ErrorIs(err, ErrInvalidComponentRef)
executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
RunID: primitives.NewUUID().String(),
}
ref := ComponentRef{
ExecutionKey: executionKey,
executionGoType: reflect.TypeFor[*TestComponent](),
executionLastUpdateVT: &persistencespb.VersionedTransition{
NamespaceFailoverVersion: rand.Int63(),
TransitionCount: rand.Int63(),
},
componentPath: []string{primitives.NewUUID().String(), primitives.NewUUID().String()},
componentInitialVT: &persistencespb.VersionedTransition{
NamespaceFailoverVersion: rand.Int63(),
TransitionCount: rand.Int63(),
},
}
serializedRef, err := ref.Serialize(s.registry)
s.NoError(err)
deserializedRef, err := DeserializeComponentRef(serializedRef)
s.NoError(err)
s.ProtoEqual(ref.executionLastUpdateVT, deserializedRef.executionLastUpdateVT)
s.ProtoEqual(ref.componentInitialVT, deserializedRef.componentInitialVT)
rootRc, ok := s.registry.ComponentFor(&TestComponent{})
s.True(ok)
s.Equal(rootRc.componentID, deserializedRef.archetypeID)
s.Equal(ref.ExecutionKey, deserializedRef.ExecutionKey)
s.Equal(ref.componentPath, deserializedRef.componentPath)
}