@@ -34,6 +34,11 @@ func simpleWorkflowWithStep(dbosCtx DBOSContext, input string) (string, error) {
3434 })
3535}
3636
37+ func slowWorkflow (dbosCtx DBOSContext , sleepTime time.Duration ) (string , error ) {
38+ time .Sleep (sleepTime )
39+ return "done" , nil
40+ }
41+
3742func simpleStep (_ context.Context ) (string , error ) {
3843 return "from step" , nil
3944}
@@ -4526,11 +4531,11 @@ func TestWorkflowIdentity(t *testing.T) {
45264531
45274532func TestWorkflowHandleTimeout (t * testing.T ) {
45284533 dbosCtx := setupDBOS (t , true , true )
4529- RegisterWorkflow (dbosCtx , simpleWorkflow )
4534+ RegisterWorkflow (dbosCtx , slowWorkflow )
45304535
45314536 t .Run ("WorkflowHandleTimeout" , func (t * testing.T ) {
45324537 // Test timeout on workflowHandle (channel-based)
4533- handle , err := RunWorkflow (dbosCtx , simpleWorkflow , "test" )
4538+ handle , err := RunWorkflow (dbosCtx , slowWorkflow , 5 * time . Second )
45344539 require .NoError (t , err , "failed to start workflow" )
45354540
45364541 // Test with a very short timeout - should timeout
@@ -4545,23 +4550,23 @@ func TestWorkflowHandleTimeout(t *testing.T) {
45454550
45464551 t .Run ("WorkflowHandleNoTimeout" , func (t * testing.T ) {
45474552 // Test without timeout - should work normally
4548- handle , err := RunWorkflow (dbosCtx , simpleWorkflow , "test" )
4553+ handle , err := RunWorkflow (dbosCtx , slowWorkflow , 1 * time . Millisecond )
45494554 require .NoError (t , err , "failed to start workflow" )
45504555
45514556 result , err := handle .GetResult ()
45524557 require .NoError (t , err , "GetResult without timeout should succeed" )
4553- assert .Equal (t , "test " , result )
4558+ assert .Equal (t , "done " , result )
45544559 })
45554560
45564561 t .Run ("WorkflowHandleGetResultAfterChannelClose" , func (t * testing.T ) {
45574562 // Test getting result after the outcome channel would be closed
4558- handle , err := RunWorkflow (dbosCtx , simpleWorkflow , "test" )
4563+ handle , err := RunWorkflow (dbosCtx , slowWorkflow , 1 * time . Millisecond )
45594564 require .NoError (t , err , "failed to start workflow" )
45604565
45614566 // Get result first time - this will close the outcome channel
45624567 result1 , err := handle .GetResult ()
45634568 require .NoError (t , err , "first GetResult should succeed" )
4564- assert .Equal (t , "test " , result1 )
4569+ assert .Equal (t , "done " , result1 )
45654570
45664571 // Sleep briefly to ensure channel is closed
45674572 time .Sleep (10 * time .Millisecond )
@@ -4575,11 +4580,11 @@ func TestWorkflowHandleTimeout(t *testing.T) {
45754580
45764581func TestWorkflowPollingHandleTimeout (t * testing.T ) {
45774582 dbosCtx := setupDBOS (t , true , true )
4578- RegisterWorkflow (dbosCtx , simpleWorkflow )
4583+ RegisterWorkflow (dbosCtx , slowWorkflow )
45794584
45804585 t .Run ("WorkflowPollingHandleTimeout" , func (t * testing.T ) {
45814586 // Test timeout on workflowPollingHandle (database polling)
4582- handle , err := RunWorkflow (dbosCtx , simpleWorkflow , "test" )
4587+ handle , err := RunWorkflow (dbosCtx , slowWorkflow , 5 * time . Second )
45834588 require .NoError (t , err , "failed to start workflow" )
45844589
45854590 // Test with a very short timeout - should timeout
@@ -4594,11 +4599,11 @@ func TestWorkflowPollingHandleTimeout(t *testing.T) {
45944599
45954600 t .Run ("WorkflowPollingHandleNoTimeout" , func (t * testing.T ) {
45964601 // Test without timeout - should work normally
4597- handle , err := RunWorkflow (dbosCtx , simpleWorkflow , "test" )
4602+ handle , err := RunWorkflow (dbosCtx , slowWorkflow , 1 * time . Millisecond )
45984603 require .NoError (t , err , "failed to start workflow" )
45994604
46004605 result , err := handle .GetResult ()
46014606 require .NoError (t , err , "GetResult without timeout should succeed" )
4602- assert .Equal (t , "test " , result )
4607+ assert .Equal (t , "done " , result )
46034608 })
46044609}
0 commit comments