Files
tasks/service/history/replication/stream_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

113 lines
3.0 KiB
Go

package replication
import (
"context"
"errors"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/metrics"
"github.com/hanzoai/tasks/common/persistence"
"github.com/hanzoai/tasks/service/history/tests"
)
func TestWrapEventLoopFn_ReturnStreamError_ShouldStopLoop(t *testing.T) {
config := tests.NewDynamicConfig()
assertion := require.New(t)
done := make(chan bool)
timer := time.NewTimer(3 * time.Second)
go func() {
originalEventLoopCallCount := 0
originalEventLoop := func() error {
originalEventLoopCallCount++
return NewStreamError("error closed", ErrClosed)
}
stopFuncCallCount := 0
stopFunc := func() {
stopFuncCallCount++
}
WrapEventLoop(context.Background(), originalEventLoop, stopFunc, log.NewNoopLogger(), metrics.NoopMetricsHandler, NewClusterShardKey(1, 1), NewClusterShardKey(2, 1), config)
assertion.Equal(1, originalEventLoopCallCount)
assertion.Equal(1, stopFuncCallCount)
done <- true
}()
select {
case <-done:
// Test completed within the timeout
case <-timer.C:
t.Fatal("Test timed out after 5 seconds")
}
}
func TestWrapEventLoopFn_ReturnShardOwnershipLostError_ShouldStopLoop(t *testing.T) {
assertion := require.New(t)
done := make(chan bool)
timer := time.NewTimer(3 * time.Second)
go func() {
originalEventLoopCallCount := 0
originalEventLoop := func() error {
originalEventLoopCallCount++
return &persistence.ShardOwnershipLostError{
ShardID: 123, // immutable
Msg: "shard closed",
}
}
stopFuncCallCount := 0
stopFunc := func() {
stopFuncCallCount++
}
WrapEventLoop(context.Background(), originalEventLoop, stopFunc, log.NewNoopLogger(), metrics.NoopMetricsHandler, NewClusterShardKey(1, 1), NewClusterShardKey(2, 1), tests.NewDynamicConfig())
assertion.Equal(1, originalEventLoopCallCount)
assertion.Equal(1, stopFuncCallCount)
done <- true
}()
select {
case <-done:
// Test completed within the timeout
case <-timer.C:
t.Fatal("Test timed out after 5 seconds")
}
}
func TestWrapEventLoopFn_ReturnServiceError_ShouldRetryUntilStreamError(t *testing.T) {
assertion := require.New(t)
done := make(chan bool)
timer := time.NewTimer(3 * time.Second)
go func() {
originalEventLoopCallCount := 0
originalEventLoop := func() error {
originalEventLoopCallCount++
if originalEventLoopCallCount == 3 {
return NewStreamError("error closed", ErrClosed)
}
return errors.New("error")
}
stopFuncCallCount := 0
stopFunc := func() {
stopFuncCallCount++
}
WrapEventLoop(context.Background(), originalEventLoop, stopFunc, log.NewNoopLogger(), metrics.NoopMetricsHandler, NewClusterShardKey(1, 1), NewClusterShardKey(2, 1), tests.NewDynamicConfig())
assertion.Equal(3, originalEventLoopCallCount)
assertion.Equal(1, stopFuncCallCount)
done <- true
}()
select {
case <-done:
// Test completed within the timeout
case <-timer.C:
t.Fatal("Test timed out after 5 seconds")
}
}