@@ -926,23 +926,17 @@ func TestQueueTimeouts(t *testing.T) {
926926 }
927927 RegisterWorkflow (dbosCtx , queuedWaitForCancelWorkflow )
928928
929- enqueuedWorkflowEnqueuesATimeoutWorkflow := func (ctx DBOSContext , _ string ) (string , error ) {
929+ enqueuedWorkflowEnqueuesATimeoutWorkflow := func (ctx DBOSContext , childWorkflowID string ) (string , error ) {
930930 // This workflow will enqueue a workflow that waits indefinitely until it is cancelled
931- handle , err := RunWorkflow (ctx , queuedWaitForCancelWorkflow , "enqueued-wait-for-cancel" , WithQueue (timeoutQueue .Name ))
931+ handle , err := RunWorkflow (ctx , queuedWaitForCancelWorkflow , "enqueued-wait-for-cancel" , WithQueue (timeoutQueue .Name ), WithWorkflowID ( childWorkflowID ) )
932932 require .NoError (t , err , "failed to start enqueued wait for cancel workflow" )
933933 // Workflow should get AwaitedWorkflowCancelled DBOSError
934934 _ , err = handle .GetResult ()
935935 require .Error (t , err , "expected error when waiting for enqueued workflow to complete, but got none" )
936936 var dbosErr * DBOSError
937937 require .ErrorAs (t , err , & dbosErr , "expected error to be of type *DBOSError, got %T" , err )
938938 assert .Equal (t , AwaitedWorkflowCancelled , dbosErr .Code , "expected error code to be AwaitedWorkflowCancelled" )
939-
940- // enqueud workflow should have been cancelled
941- status , err := handle .GetStatus ()
942- require .NoError (t , err , "failed to get status of enqueued workflow" )
943- assert .Equal (t , WorkflowStatusCancelled , status .Status , "expected enqueued workflow status to be WorkflowStatusCancelled" )
944-
945- return "should-never-see-this" , nil
939+ return "" , nil
946940 }
947941 RegisterWorkflow (dbosCtx , enqueuedWorkflowEnqueuesATimeoutWorkflow )
948942
@@ -956,19 +950,20 @@ func TestQueueTimeouts(t *testing.T) {
956950 }
957951
958952 enqueuedWorkflowEnqueuesADetachedWorkflow := func (ctx DBOSContext , timeout time.Duration ) (string , error ) {
953+ myId , err := GetWorkflowID (ctx )
954+ if err != nil {
955+ return "" , fmt .Errorf ("failed to get workflow ID: %v" , err )
956+ }
957+ childID := fmt .Sprintf ("%s-child" , myId )
959958 // This workflow will enqueue a workflow that is not cancelable
960959 childCtx := WithoutCancel (ctx )
961- handle , err := RunWorkflow (childCtx , detachedWorkflow , timeout * 2 , WithQueue (timeoutQueue .Name ))
960+ handle , err := RunWorkflow (childCtx , detachedWorkflow , timeout * 2 , WithQueue (timeoutQueue .Name ), WithWorkflowID ( childID ) )
962961 require .NoError (t , err , "failed to start enqueued detached workflow" )
963962
964963 // Wait for the enqueued workflow to complete
965964 result , err := handle .GetResult ()
966965 require .NoError (t , err , "failed to get result from enqueued detached workflow" )
967966 assert .Equal (t , "detached-workflow-completed" , result , "expected result to be 'detached-workflow-completed'" )
968- // Check the workflow status: should be success
969- status , err := handle .GetStatus ()
970- require .NoError (t , err , "failed to get enqueued detached workflow status" )
971- assert .Equal (t , WorkflowStatusSuccess , status .Status , "expected enqueued detached workflow status to be WorkflowStatusSuccess" )
972967 return result , nil
973968 }
974969
@@ -1022,7 +1017,8 @@ func TestQueueTimeouts(t *testing.T) {
10221017 cancelCtx , cancelFunc := WithTimeout (dbosCtx , 1 * time .Millisecond )
10231018 defer cancelFunc () // Ensure we clean up the context
10241019
1025- handle , err := RunWorkflow (cancelCtx , enqueuedWorkflowEnqueuesATimeoutWorkflow , "enqueue-timeout-workflow" , WithQueue (timeoutQueue .Name ))
1020+ childWorkflowID := uuid .NewString ()
1021+ handle , err := RunWorkflow (cancelCtx , enqueuedWorkflowEnqueuesATimeoutWorkflow , childWorkflowID , WithQueue (timeoutQueue .Name ))
10261022 require .NoError (t , err , "failed to start enqueued workflow" )
10271023
10281024 // Wait for the workflow to complete and get the result
@@ -1042,6 +1038,18 @@ func TestQueueTimeouts(t *testing.T) {
10421038 require .NoError (t , err , "failed to get workflow status" )
10431039 assert .Equal (t , WorkflowStatusCancelled , status .Status , "expected workflow status to be WorkflowStatusCancelled" )
10441040
1041+ // Wait for the child workflow status to become cancelled
1042+ require .Eventually (t , func () bool {
1043+ childHandle , err := RetrieveWorkflow [string ](dbosCtx , childWorkflowID )
1044+ require .NoError (t , err , "failed to retrieve child workflow" )
1045+
1046+ status , err := childHandle .GetStatus ()
1047+ if err != nil {
1048+ return false
1049+ }
1050+ return status .Status == WorkflowStatusCancelled
1051+ }, 5 * time .Second , 100 * time .Millisecond , "expected enqueued workflow status to be WorkflowStatusCancelled" )
1052+
10451053 require .True (t , queueEntriesAreCleanedUp (dbosCtx ), "expected queue entries to be cleaned up after workflow cancellation, but they are not" )
10461054 })
10471055
@@ -1071,6 +1079,19 @@ func TestQueueTimeouts(t *testing.T) {
10711079 require .NoError (t , err , "failed to get enqueued detached workflow status" )
10721080 assert .Equal (t , WorkflowStatusCancelled , status .Status , "expected enqueued detached workflow status to be WorkflowStatusCancelled" )
10731081
1082+ // Check the child's status: should be success because it is detached
1083+ require .Eventually (t , func () bool {
1084+ childID := fmt .Sprintf ("%s-child" , handle .GetWorkflowID ())
1085+ childHandle , err := RetrieveWorkflow [string ](dbosCtx , childID )
1086+ require .NoError (t , err , "failed to retrieve detached workflow" )
1087+
1088+ status , err := childHandle .GetStatus ()
1089+ if err != nil {
1090+ return false
1091+ }
1092+ return status .Status == WorkflowStatusSuccess
1093+ }, 5 * time .Second , 100 * time .Millisecond , "expected detached workflow status to be WorkflowStatusSuccess" )
1094+
10741095 require .True (t , queueEntriesAreCleanedUp (dbosCtx ), "expected queue entries to be cleaned up after workflow cancellation, but they are not" )
10751096 })
10761097
0 commit comments