Files
tasks/tools/tdbg/tdbgtest/output_parsing_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

105 lines
2.9 KiB
Go

package tdbgtest_test
import (
"bytes"
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
"go.temporal.io/api/workflowservice/v1"
"github.com/hanzoai/tasks/api/adminservice/v1"
commonspb "github.com/hanzoai/tasks/api/common/v1"
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
"github.com/hanzoai/tasks/common/definition"
"github.com/hanzoai/tasks/common/persistence/serialization"
"github.com/hanzoai/tasks/service/history/tasks"
"github.com/hanzoai/tasks/service/history/tests"
"github.com/hanzoai/tasks/tools/tdbg"
"github.com/hanzoai/tasks/tools/tdbg/tdbgtest"
"google.golang.org/grpc"
)
type (
testClient struct {
adminservice.AdminServiceClient
getDLQTasksFn func(request *adminservice.GetDLQTasksRequest) (*adminservice.GetDLQTasksResponse, error)
}
)
// TestParseDLQMessages tests that [tdbgtest.ParseDLQMessages] can parse a JSONL file containing serialized tasks.
func TestParseDLQMessages(t *testing.T) {
t.Parallel()
task := &tasks.WorkflowTask{
WorkflowKey: definition.WorkflowKey{
WorkflowID: tests.WorkflowID,
},
TaskID: 13,
}
taskSerializer := serialization.NewSerializer()
blob, err := taskSerializer.SerializeTask(task)
require.NoError(t, err)
client := &testClient{
getDLQTasksFn: func(request *adminservice.GetDLQTasksRequest) (*adminservice.GetDLQTasksResponse, error) {
return &adminservice.GetDLQTasksResponse{
DlqTasks: []*commonspb.HistoryDLQTask{{
Metadata: &commonspb.HistoryDLQTaskMetadata{
MessageId: 21,
},
Payload: &commonspb.HistoryTask{
ShardId: 34,
Blob: blob,
},
},
},
}, nil
},
}
var b bytes.Buffer
app := tdbgtest.NewCliApp(func(params *tdbg.Params) {
params.ClientFactory = client
params.Writer = &b
})
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
t.Cleanup(cancel)
err = app.RunContext(ctx, []string{
"tdbg",
"--" + tdbg.FlagYes,
"dlq",
"read",
"--" + tdbg.FlagDLQType, "1",
"--" + tdbg.FlagTargetCluster, "test-target-cluster",
})
require.NoError(t, err)
output := b.String()
t.Log("output:", output)
messages, err := tdbgtest.ParseDLQMessages(&b, func() *persistencespb.TransferTaskInfo {
return new(persistencespb.TransferTaskInfo)
})
require.NoError(t, err)
require.Len(t, messages, 1)
message := messages[0]
assert.Equal(t, 13, int(message.Payload.TaskId))
assert.Equal(t, 21, int(message.MessageID))
assert.Equal(t, 34, int(message.ShardID))
}
func (t *testClient) AdminClient(*cli.Context) adminservice.AdminServiceClient {
return t
}
func (t *testClient) WorkflowClient(*cli.Context) workflowservice.WorkflowServiceClient {
panic("unimplemented")
}
func (t *testClient) GetDLQTasks(
_ context.Context,
request *adminservice.GetDLQTasksRequest,
_ ...grpc.CallOption,
) (*adminservice.GetDLQTasksResponse, error) {
return t.getDLQTasksFn(request)
}