Files
temporal/tests/testcore/matching_behavior.go
Shahab Tajik c973dc1996 Address dnr review comments on #9395 (#9539)
## Summary
Follow-up to #9395 addressing review comments:
- Fix comment table alignment to use spaces instead of tabs for correct
GitHub rendering
- Simplify nil check in `getCreateTime` using proto getter (handles nil
receiver)
- Rename `runSuiteWithMatchingBehaviors` →
`runTaskQueueStatsSuiteWithMatchingBehaviors` (suite-specific)
- Remove redundant `MatchingUseNewMatcher` from test opts (already set
globally in functional tests)
- Move `MatchingForwarderMaxChildrenPerNode` into
`MatchingBehavior.Options()`

## Test plan
- [x] Builds with `-tags test_dep`
- [ ] Existing functional tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 00:09:30 +00:00

92 lines
2.6 KiB
Go

package testcore
import (
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/testing/testhooks"
)
// MatchingBehavior describes a test scenario for matching service behavior.
type MatchingBehavior struct {
ForceTaskForward bool
ForcePollForward bool
ForceAsync bool
}
type hookInjector interface {
InjectHook(hook testhooks.Hook) (cleanup func())
}
// Name returns a descriptive name for this behavior combination.
func (b MatchingBehavior) Name() string {
name := "NoTaskForward"
if b.ForceTaskForward {
name = "ForceTaskForward"
}
if b.ForcePollForward {
name += "ForcePollForward"
} else {
name += "NoPollForward"
}
if b.ForceAsync {
name += "ForceAsync"
} else {
name += "AllowSync"
}
return name
}
// Options returns the TestOptions to configure matching behavior.
func (b MatchingBehavior) Options() []TestOption {
opts := []TestOption{
WithDynamicConfig(dynamicconfig.MatchingForwarderMaxChildrenPerNode, 3),
}
if b.ForceTaskForward || b.ForcePollForward {
opts = append(opts,
WithDynamicConfig(dynamicconfig.MatchingNumTaskqueueReadPartitions, 13),
WithDynamicConfig(dynamicconfig.MatchingNumTaskqueueWritePartitions, 13),
)
} else {
opts = append(opts,
WithDynamicConfig(dynamicconfig.MatchingNumTaskqueueReadPartitions, 1),
WithDynamicConfig(dynamicconfig.MatchingNumTaskqueueWritePartitions, 1),
)
}
return opts
}
// InjectHooks injects the test hooks for this matching behavior.
func (b MatchingBehavior) InjectHooks(env hookInjector) {
if b.ForceTaskForward {
env.InjectHook(testhooks.NewHook(testhooks.MatchingLBForceWritePartition, 11))
} else {
env.InjectHook(testhooks.NewHook(testhooks.MatchingLBForceWritePartition, 0))
}
if b.ForcePollForward {
env.InjectHook(testhooks.NewHook(testhooks.MatchingLBForceReadPartition, 5))
} else {
env.InjectHook(testhooks.NewHook(testhooks.MatchingLBForceReadPartition, 0))
}
if b.ForceAsync {
env.InjectHook(testhooks.NewHook(testhooks.MatchingDisableSyncMatch, true))
} else {
env.InjectHook(testhooks.NewHook(testhooks.MatchingDisableSyncMatch, false))
}
}
// AllMatchingBehaviors returns all 8 combinations of matching behaviors for testing.
func AllMatchingBehaviors() []MatchingBehavior {
var behaviors []MatchingBehavior
for _, forcePollForward := range []bool{false, true} {
for _, forceTaskForward := range []bool{false, true} {
for _, forceAsync := range []bool{false, true} {
behaviors = append(behaviors, MatchingBehavior{
ForceTaskForward: forceTaskForward,
ForcePollForward: forcePollForward,
ForceAsync: forceAsync,
})
}
}
}
return behaviors
}