@@ -35,19 +35,23 @@ func simpleWorkflowError(dbosCtx DBOSContext, input string) (int, error) {
3535}
3636
3737func simpleWorkflowWithStep (dbosCtx DBOSContext , input string ) (string , error ) {
38- return RunAsStep (dbosCtx , simpleStep , input )
38+ return RunAsStep [string ](dbosCtx , func (ctx context.Context ) (string , error ) {
39+ return simpleStep (ctx )
40+ })
3941}
4042
41- func simpleStep (ctx context.Context , input string ) (string , error ) {
43+ func simpleStep (_ context.Context ) (string , error ) {
4244 return "from step" , nil
4345}
4446
45- func simpleStepError (ctx context.Context , input string ) (string , error ) {
47+ func simpleStepError (_ context.Context ) (string , error ) {
4648 return "" , fmt .Errorf ("step failure" )
4749}
4850
4951func simpleWorkflowWithStepError (dbosCtx DBOSContext , input string ) (string , error ) {
50- return RunAsStep (dbosCtx , simpleStepError , input )
52+ return RunAsStep [string ](dbosCtx , func (ctx context.Context ) (string , error ) {
53+ return simpleStepError (ctx )
54+ })
5155}
5256
5357// idempotencyWorkflow increments a global counter and returns the input
@@ -292,38 +296,44 @@ func TestWorkflowsRegistration(t *testing.T) {
292296 }
293297}
294298
295- func stepWithinAStep (ctx context.Context , input string ) (string , error ) {
296- return simpleStep (ctx , input )
299+ func stepWithinAStep (ctx context.Context ) (string , error ) {
300+ return simpleStep (ctx )
297301}
298302
299303func stepWithinAStepWorkflow (dbosCtx DBOSContext , input string ) (string , error ) {
300- return RunAsStep (dbosCtx , stepWithinAStep , input )
304+ return RunAsStep [string ](dbosCtx , func (ctx context.Context ) (string , error ) {
305+ return stepWithinAStep (ctx )
306+ })
301307}
302308
303309// Global counter for retry testing
304310var stepRetryAttemptCount int
305311
306- func stepRetryAlwaysFailsStep (ctx context.Context , input string ) (string , error ) {
312+ func stepRetryAlwaysFailsStep (ctx context.Context ) (string , error ) {
307313 stepRetryAttemptCount ++
308314 return "" , fmt .Errorf ("always fails - attempt %d" , stepRetryAttemptCount )
309315}
310316
311317var stepIdempotencyCounter int
312318
313- func stepIdempotencyTest (ctx context.Context , input int ) (string , error ) {
319+ func stepIdempotencyTest (ctx context.Context ) (string , error ) {
314320 stepIdempotencyCounter ++
315321 return "" , nil
316322}
317323
318324func stepRetryWorkflow (dbosCtx DBOSContext , input string ) (string , error ) {
319- RunAsStep (dbosCtx , stepIdempotencyTest , 1 )
325+ RunAsStep [int ](dbosCtx , func (ctx context.Context ) (string , error ) {
326+ return stepIdempotencyTest (ctx )
327+ })
320328 stepCtx := WithValue (dbosCtx , StepParamsKey , & StepParams {
321329 MaxRetries : 5 ,
322330 BaseInterval : 1 * time .Millisecond ,
323331 MaxInterval : 10 * time .Millisecond ,
324332 })
325333
326- return RunAsStep (stepCtx , stepRetryAlwaysFailsStep , input )
334+ return RunAsStep [string ](stepCtx , func (ctx context.Context ) (string , error ) {
335+ return stepRetryAlwaysFailsStep (ctx )
336+ })
327337}
328338
329339func TestSteps (t * testing.T ) {
@@ -335,7 +345,9 @@ func TestSteps(t *testing.T) {
335345
336346 t .Run ("StepsMustRunInsideWorkflows" , func (t * testing.T ) {
337347 // Attempt to run a step outside of a workflow context
338- _ , err := RunAsStep (dbosCtx , simpleStep , "test" )
348+ _ , err := RunAsStep [int ](dbosCtx , func (ctx context.Context ) (string , error ) {
349+ return simpleStep (ctx )
350+ })
339351 if err == nil {
340352 t .Fatal ("expected error when running step outside of workflow context, but got none" )
341353 }
@@ -470,7 +482,9 @@ func TestChildWorkflow(t *testing.T) {
470482 return "" , fmt .Errorf ("expected childWf workflow ID to be %s, got %s" , expectedCurrentID , workflowID )
471483 }
472484 // Steps of a child workflow start with an incremented step ID, because the first step ID is allocated to the child workflow
473- return RunAsStep (dbosCtx , simpleStep , "" )
485+ return RunAsStep [string ](dbosCtx , func (ctx context.Context ) (string , error ) {
486+ return simpleStep (ctx )
487+ })
474488 }
475489 RegisterWorkflow (dbosCtx , childWf )
476490
@@ -644,7 +658,9 @@ func TestChildWorkflow(t *testing.T) {
644658 customChildID := uuid .NewString ()
645659
646660 simpleChildWf := func (dbosCtx DBOSContext , input string ) (string , error ) {
647- return RunAsStep (dbosCtx , simpleStep , input )
661+ return RunAsStep [string ](dbosCtx , func (ctx context.Context ) (string , error ) {
662+ return simpleStep (ctx )
663+ })
648664 }
649665 RegisterWorkflow (dbosCtx , simpleChildWf )
650666
@@ -713,23 +729,29 @@ func TestChildWorkflow(t *testing.T) {
713729// Idempotency workflows moved to test functions
714730
715731func idempotencyWorkflow (dbosCtx DBOSContext , input string ) (string , error ) {
716- RunAsStep (dbosCtx , incrementCounter , int64 (1 ))
732+ RunAsStep [int64 ](dbosCtx , func (ctx context.Context ) (int64 , error ) {
733+ return incrementCounter (ctx , int64 (1 ))
734+ })
717735 return input , nil
718736}
719737
720738var blockingStepStopEvent * Event
721739
722- func blockingStep (ctx context.Context , input string ) (string , error ) {
740+ func blockingStep (_ context.Context ) (string , error ) {
723741 blockingStepStopEvent .Wait ()
724742 return "" , nil
725743}
726744
727745var idempotencyWorkflowWithStepEvent * Event
728746
729747func idempotencyWorkflowWithStep (dbosCtx DBOSContext , input string ) (int64 , error ) {
730- RunAsStep (dbosCtx , incrementCounter , int64 (1 ))
748+ RunAsStep [int64 ](dbosCtx , func (ctx context.Context ) (int64 , error ) {
749+ return incrementCounter (ctx , int64 (1 ))
750+ })
731751 idempotencyWorkflowWithStepEvent .Set ()
732- RunAsStep (dbosCtx , blockingStep , input )
752+ RunAsStep [int ](dbosCtx , func (ctx context.Context ) (string , error ) {
753+ return blockingStep (ctx )
754+ })
733755 return idempotencyCounter , nil
734756}
735757
@@ -1253,7 +1275,9 @@ func stepThatCallsSend(ctx context.Context, input sendWorkflowInput) (string, er
12531275}
12541276
12551277func workflowThatCallsSendInStep (ctx DBOSContext , input sendWorkflowInput ) (string , error ) {
1256- return RunAsStep (ctx , stepThatCallsSend , input )
1278+ return RunAsStep [sendWorkflowInput ](ctx , func (context context.Context ) (string , error ) {
1279+ return stepThatCallsSend (context , input )
1280+ })
12571281}
12581282
12591283type sendRecvType struct {
@@ -2193,7 +2217,7 @@ func TestWorkflowTimeout(t *testing.T) {
21932217 }
21942218 })
21952219
2196- waitForCancelStep := func (ctx context.Context , _ string ) (string , error ) {
2220+ waitForCancelStep := func (ctx context.Context ) (string , error ) {
21972221 // This step will trigger cancellation of the entire workflow context
21982222 <- ctx .Done ()
21992223 if ! errors .Is (ctx .Err (), context .Canceled ) && ! errors .Is (ctx .Err (), context .DeadlineExceeded ) {
@@ -2203,7 +2227,9 @@ func TestWorkflowTimeout(t *testing.T) {
22032227 }
22042228
22052229 waitForCancelWorkflowWithStep := func (ctx DBOSContext , _ string ) (string , error ) {
2206- return RunAsStep (ctx , waitForCancelStep , "trigger-cancellation" )
2230+ return RunAsStep [sendWorkflowInput ](ctx , func (context context.Context ) (string , error ) {
2231+ return waitForCancelStep (context )
2232+ })
22072233 }
22082234 RegisterWorkflow (dbosCtx , waitForCancelWorkflowWithStep )
22092235
@@ -2240,7 +2266,9 @@ func TestWorkflowTimeout(t *testing.T) {
22402266 // The timeout will trigger a step error, the workflow can do whatever it wants with that error
22412267 stepCtx , stepCancelFunc := WithTimeout (ctx , 1 * time .Millisecond )
22422268 defer stepCancelFunc () // Ensure we clean up the context
2243- _ , err := RunAsStep (stepCtx , waitForCancelStep , "short-step-timeout" )
2269+ _ , err := RunAsStep [string ](stepCtx , func (context context.Context ) (string , error ) {
2270+ return waitForCancelStep (context )
2271+ })
22442272 if ! errors .Is (err , context .DeadlineExceeded ) {
22452273 t .Fatalf ("expected step to timeout, got: %v" , err )
22462274 }
@@ -2287,7 +2315,9 @@ func TestWorkflowTimeout(t *testing.T) {
22872315 // This workflow will run a step that is not cancelable.
22882316 // What this means is the workflow *will* be cancelled, but the step will run normally
22892317 stepCtx := WithoutCancel (ctx )
2290- res , err := RunAsStep (stepCtx , detachedStep , timeout * 2 )
2318+ res , err := RunAsStep [time.Duration ](stepCtx , func (context context.Context ) (string , error ) {
2319+ return detachedStep (context , timeout * 2 )
2320+ })
22912321 if err != nil {
22922322 t .Fatalf ("failed to run detached step: %v" , err )
22932323 }
0 commit comments