Skip to content

Commit 370d33e

Browse files
committed
test some more signatures
1 parent 1a6a950 commit 370d33e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

dbos/serialization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (g *gobSerializer[T]) Encode(data T) (string, error) {
6868
encoder := gob.NewEncoder(&buf)
6969
wrapper := gobValue{Value: data}
7070
if err := encoder.Encode(wrapper); err != nil {
71-
return "", fmt.Errorf("failed to encode data with gob: %w", err)
71+
return "", fmt.Errorf("failed to encode data: %w", err)
7272
}
7373
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
7474
}

dbos/serialization_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ func testSetGetEvent[T any](
222222

223223
type MyInt int
224224
type MyString string
225+
type IntSliceSlice [][]int
225226

226227
// Test data structures for DBOS integration testing
227228
type TestData struct {
@@ -302,6 +303,11 @@ var (
302303
recoveryMyStringWorkflow = makeRecoveryWorkflow[MyString]()
303304
recoveryMyStringSliceWorkflow = makeRecoveryWorkflow[[]MyString]()
304305
recoveryStringMyIntMapWorkflow = makeRecoveryWorkflow[map[string]MyInt]()
306+
// Additional types: empty struct, nested collections, slices of pointers
307+
recoveryEmptyStructWorkflow = makeRecoveryWorkflow[struct{}]()
308+
recoveryIntSliceSliceWorkflow = makeRecoveryWorkflow[IntSliceSlice]()
309+
recoveryNestedMapWorkflow = makeRecoveryWorkflow[map[string]map[string]int]()
310+
recoveryIntPtrSliceWorkflow = makeRecoveryWorkflow[[]*int]()
305311
)
306312

307313
// makeSenderWorkflow creates a generic sender workflow that sends a message to a receiver workflow.
@@ -578,6 +584,11 @@ func TestSerializer(t *testing.T) {
578584
RegisterWorkflow(executor, recoveryMyStringWorkflow)
579585
RegisterWorkflow(executor, recoveryMyStringSliceWorkflow)
580586
RegisterWorkflow(executor, recoveryStringMyIntMapWorkflow)
587+
// Register additional recovery workflows
588+
RegisterWorkflow(executor, recoveryEmptyStructWorkflow)
589+
RegisterWorkflow(executor, recoveryIntSliceSliceWorkflow)
590+
RegisterWorkflow(executor, recoveryNestedMapWorkflow)
591+
RegisterWorkflow(executor, recoveryIntPtrSliceWorkflow)
581592
// Register typed Send/Recv workflows
582593
RegisterWorkflow(executor, serializerIntSenderWorkflow)
583594
RegisterWorkflow(executor, serializerIntReceiverWorkflow)
@@ -877,6 +888,44 @@ func TestSerializer(t *testing.T) {
877888
})
878889
})
879890

891+
// Empty struct
892+
t.Run("EmptyStruct", func(t *testing.T) {
893+
input := struct{}{}
894+
testAllSerializationPaths(t, executor, recoveryEmptyStructWorkflow, input, "recovery-empty-struct-wf")
895+
})
896+
897+
// Nested collections
898+
t.Run("NestedCollections", func(t *testing.T) {
899+
t.Run("SliceOfSlices", func(t *testing.T) {
900+
input := IntSliceSlice{{1, 2}, {3, 4, 5}}
901+
testAllSerializationPaths(t, executor, recoveryIntSliceSliceWorkflow, input, "recovery-int-slice-slice-wf")
902+
})
903+
904+
t.Run("NestedMap", func(t *testing.T) {
905+
input := map[string]map[string]int{
906+
"outer1": {"inner1": 1, "inner2": 2},
907+
"outer2": {"inner3": 3},
908+
}
909+
testAllSerializationPaths(t, executor, recoveryNestedMapWorkflow, input, "recovery-nested-map-wf")
910+
})
911+
})
912+
913+
// Slices of pointers
914+
t.Run("SliceOfPointers", func(t *testing.T) {
915+
t.Run("NonNil", func(t *testing.T) {
916+
v1 := 10
917+
v2 := 20
918+
v3 := 30
919+
input := []*int{&v1, &v2, &v3}
920+
testAllSerializationPaths(t, executor, recoveryIntPtrSliceWorkflow, input, "recovery-int-ptr-slice-wf")
921+
})
922+
923+
t.Run("NilSlice", func(t *testing.T) {
924+
var input []*int = nil
925+
testAllSerializationPaths(t, executor, recoveryIntPtrSliceWorkflow, input, "recovery-int-ptr-slice-nil-wf")
926+
})
927+
})
928+
880929
// Test workflow with interface signature and manual gob registration
881930
t.Run("InterfaceWithManualGobRegistration", func(t *testing.T) {
882931
// Create an instance of the concrete implementation

dbos/workflows_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,6 @@ func TestChildWorkflow(t *testing.T) {
963963
require.NoError(t, err, "failed to launch DBOS")
964964

965965
t.Run("ChildWorkflowIDGeneration", func(t *testing.T) {
966-
967966
r := 3
968967
h, err := RunWorkflow(dbosCtx, grandParentWf, r)
969968
require.NoError(t, err, "failed to execute grand parent workflow")

0 commit comments

Comments
 (0)