Skip to content

Commit c48821f

Browse files
committed
update tests
1 parent 7950464 commit c48821f

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

dbos/client_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ func TestCancelResume(t *testing.T) {
372372
result, err := resumeHandle.GetResult()
373373
require.NoError(t, err, "failed to get result from resumed workflow")
374374

375-
// Verify the result
376-
assert.Equal(t, input, result, "expected result to match input")
375+
// Verify the result. Need to recast to int because JSON serialized it
376+
assert.Equal(t, input, int(result.(float64)), "expected result to match input")
377377

378378
// Verify both steps completed
379379
assert.Equal(t, 2, stepsCompleted, "expected steps completed to be 2")
@@ -394,7 +394,8 @@ func TestCancelResume(t *testing.T) {
394394
resultAgain, err := resumeAgainHandle.GetResult()
395395
require.NoError(t, err, "failed to get result from second resume")
396396

397-
assert.Equal(t, input, resultAgain, "expected second resume result to match input")
397+
// Need to recast to int because JSON serialized it to float64
398+
assert.Equal(t, input, int(resultAgain.(float64)), "expected second resume result to match input")
398399

399400
// Verify steps didn't run again
400401
assert.Equal(t, 2, stepsCompleted, "expected steps completed to remain 2 after second resume")

dbos/queues_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,9 @@ func TestQueueRecovery(t *testing.T) {
540540
// Root workflow case
541541
result, err := h.GetResult()
542542
require.NoError(t, err, "failed to get result from recovered root workflow handle")
543-
castedResult, ok := result.([]int)
544-
require.True(t, ok, "expected result to be of type []int for root workflow, got %T", result)
543+
// Need to re-marshal to []int because JSON serialized it to []interface{}
544+
castedResult, err := convertJSONToType[[]int](result)
545+
require.NoError(t, err, "failed to convert result to []int")
545546
expectedResult := []int{0, 1, 2, 3, 4}
546547
assert.Equal(t, expectedResult, castedResult, "expected result %v, got %v", expectedResult, castedResult)
547548
}

dbos/workflow.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,8 @@ func (c *dbosContext) RunWorkflow(_ DBOSContext, fn WorkflowFunc, input any, opt
976976
result, err = fn(workflowCtx, input)
977977

978978
// Handle DBOS ID conflict errors by waiting workflow result
979-
needsConversion := false
979+
needsConversion := false // Notify the handle.GetResult() that we need to decode the result.
980980
if errors.Is(err, &DBOSError{Code: ConflictingIDError}) {
981-
fmt.Println("Detected workflow ID conflict error, awaiting existing workflow result")
982981
c.logger.Warn("Workflow ID conflict detected. Waiting for existing workflow to complete", "workflow_id", workflowID)
983982
result, err = retryWithResult(c, func() (any, error) {
984983
return c.systemDB.awaitWorkflowResult(uncancellableCtx, workflowID)

dbos/workflows_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ func TestSteps(t *testing.T) {
827827
})
828828

829829
t.Run("stepsOutputEncoding", func(t *testing.T) {
830-
831830
// Execute the workflow
832831
handle, err := RunWorkflow(dbosCtx, userObjectWorkflow, "TestObject")
833832
require.NoError(t, err, "failed to run workflow with user-defined objects")
@@ -846,17 +845,20 @@ func TestSteps(t *testing.T) {
846845
require.NotNil(t, step.Output, "step output should not be nil")
847846
assert.Nil(t, step.Error)
848847

848+
fmt.Println("step.Output", step.Output)
849+
849850
// Deserialize the output from the database to verify proper encoding
850-
storedOutput, ok := step.Output.(StepOutput)
851-
require.True(t, ok, "failed to cast step output to StepOutput")
851+
// Need to recast to JSON because step.Output is an any type
852+
storedOutput, err := convertJSONToType[StepOutput](step.Output)
853+
require.NoError(t, err)
852854

853855
// Verify all fields were correctly serialized and deserialized
854-
assert.Equal(t, "Processed_TestObject", storedOutput.ProcessedName, "ProcessedName not correctly serialized")
855-
assert.Equal(t, 84, storedOutput.TotalCount, "TotalCount not correctly serialized")
856-
assert.True(t, storedOutput.Success, "Success flag not correctly serialized")
857-
assert.Len(t, storedOutput.Details, 3, "Details array length incorrect")
858-
assert.Equal(t, []string{"step1", "step2", "step3"}, storedOutput.Details, "Details array not correctly serialized")
859-
assert.False(t, storedOutput.ProcessedAt.IsZero(), "ProcessedAt timestamp should not be zero")
856+
assert.Equal(t, "Processed_TestObject", storedOutput.ProcessedName)
857+
assert.Equal(t, 84, storedOutput.TotalCount)
858+
assert.True(t, storedOutput.Success)
859+
assert.Len(t, storedOutput.Details, 3)
860+
assert.Equal(t, []string{"step1", "step2", "step3"}, storedOutput.Details)
861+
assert.False(t, storedOutput.ProcessedAt.IsZero())
860862
})
861863
}
862864

@@ -1412,8 +1414,8 @@ func TestWorkflowRecovery(t *testing.T) {
14121414
result, err := recoveredHandle.GetResult()
14131415
require.NoError(t, err, "failed to get result from recovered workflow %d", i)
14141416

1415-
// Result should be the counter value (1)
1416-
require.Equal(t, int64(1), result, "workflow %d result should be 1", i)
1417+
// Result should be the counter value (1). Will be float64 because JSON serialized it into an any type.
1418+
require.Equal(t, float64(1), result, "workflow %d result should be 1", i)
14171419
}
14181420

14191421
// Final verification of step states
@@ -1578,7 +1580,8 @@ func TestWorkflowDeadLetterQueue(t *testing.T) {
15781580
for i, h := range handles {
15791581
result, err := h.GetResult()
15801582
require.NoError(t, err, "failed to get result from handle %d", i)
1581-
require.Equal(t, 0, result)
1583+
// Will be float64 because JSON serialized it into an any type.
1584+
require.Equal(t, float64(0), result)
15821585
}
15831586
})
15841587
}

0 commit comments

Comments
 (0)