@@ -47,6 +47,10 @@ func simpleWorkflowWithStepError(dbosCtx DBOSContext, input string) (string, err
4747 })
4848}
4949
50+ func simpleWorkflowWithSchedule (dbosCtx DBOSContext , scheduledTime time.Time ) (time.Time , error ) {
51+ return scheduledTime , nil
52+ }
53+
5054// idempotencyWorkflow increments a global counter and returns the input
5155func incrementCounter (_ context.Context , value int64 ) (int64 , error ) {
5256 idempotencyCounter += value
@@ -4238,6 +4242,73 @@ func TestSpecialSteps(t *testing.T) {
42384242 require .Equal (t , "success" , result , "workflow should return success" )
42394243 })
42404244}
4245+
4246+ func TestRegisteredWorkflowListing (t * testing.T ) {
4247+ dbosCtx := setupDBOS (t , true , true )
4248+
4249+ // Register some regular workflows
4250+ RegisterWorkflow (dbosCtx , simpleWorkflow )
4251+ RegisterWorkflow (dbosCtx , simpleWorkflowError , WithMaxRetries (5 ))
4252+ RegisterWorkflow (dbosCtx , simpleWorkflowWithStep , WithWorkflowName ("CustomStepWorkflow" ))
4253+ RegisterWorkflow (dbosCtx , simpleWorkflowWithSchedule , WithWorkflowName ("ScheduledWorkflow" ), WithSchedule ("0 0 * * * *" ))
4254+
4255+ err := Launch (dbosCtx )
4256+ require .NoError (t , err , "failed to launch DBOS" )
4257+
4258+ t .Run ("ListRegisteredWorkflows" , func (t * testing.T ) {
4259+ workflows , err := ListRegisteredWorkflows (dbosCtx )
4260+ require .NoError (t , err , "ListRegisteredWorkflows should not return an error" )
4261+
4262+ // Should have 4 workflows (3 regular + 1 scheduled)
4263+ require .GreaterOrEqual (t , len (workflows ), 4 , "Should have 4 registered workflows" )
4264+
4265+ // Create a map for easier lookup
4266+ workflowMap := make (map [string ]WorkflowRegistryEntry )
4267+ for _ , wf := range workflows {
4268+ workflowMap [wf .FQN ] = wf
4269+ }
4270+
4271+ // Check that simpleWorkflow is registered
4272+ simpleWorkflowFQN := runtime .FuncForPC (reflect .ValueOf (simpleWorkflow ).Pointer ()).Name ()
4273+ simpleWf , exists := workflowMap [simpleWorkflowFQN ]
4274+ require .True (t , exists , "simpleWorkflow should be registered" )
4275+ require .Equal (t , _DEFAULT_MAX_RECOVERY_ATTEMPTS , simpleWf .MaxRetries , "simpleWorkflow should have default max retries" )
4276+ require .Empty (t , simpleWf .CronSchedule , "simpleWorkflow should not have cron schedule" )
4277+
4278+ // Check that simpleWorkflowError is registered with custom max retries
4279+ simpleWorkflowErrorFQN := runtime .FuncForPC (reflect .ValueOf (simpleWorkflowError ).Pointer ()).Name ()
4280+ errorWf , exists := workflowMap [simpleWorkflowErrorFQN ]
4281+ require .True (t , exists , "simpleWorkflowError should be registered" )
4282+ require .Equal (t , 5 , errorWf .MaxRetries , "simpleWorkflowError should have custom max retries" )
4283+ require .Empty (t , errorWf .CronSchedule , "simpleWorkflowError should not have cron schedule" )
4284+
4285+ // Check that custom named workflow is registered
4286+ customStepWorkflowFQN := runtime .FuncForPC (reflect .ValueOf (simpleWorkflowWithStep ).Pointer ()).Name ()
4287+ customWf , exists := workflowMap [customStepWorkflowFQN ]
4288+ require .True (t , exists , "CustomStepWorkflow should be found" )
4289+ require .Equal (t , "CustomStepWorkflow" , customWf .Name , "CustomStepWorkflow should have the correct name" )
4290+ require .Empty (t , customWf .CronSchedule , "CustomStepWorkflow should not have cron schedule" )
4291+
4292+ // Check that scheduled workflow is registered
4293+ scheduledWorkflowFQN := runtime .FuncForPC (reflect .ValueOf (simpleWorkflowWithSchedule ).Pointer ()).Name ()
4294+ scheduledWf , exists := workflowMap [scheduledWorkflowFQN ]
4295+ require .True (t , exists , "ScheduledWorkflow should be found" )
4296+ require .Equal (t , "ScheduledWorkflow" , scheduledWf .Name , "ScheduledWorkflow should have the correct name" )
4297+ require .Equal (t , "0 0 * * * *" , scheduledWf .CronSchedule , "ScheduledWorkflow should have the correct cron schedule" )
4298+ })
4299+
4300+ t .Run ("ListRegisteredWorkflowsWithScheduledOnly" , func (t * testing.T ) {
4301+ scheduledWorkflows , err := ListRegisteredWorkflows (dbosCtx , WithScheduledOnly ())
4302+ require .NoError (t , err , "ListRegisteredWorkflows with WithScheduledOnly should not return an error" )
4303+ require .Equal (t , 1 , len (scheduledWorkflows ), "Should have exactly 1 scheduled workflow" )
4304+
4305+ entry := scheduledWorkflows [0 ]
4306+ scheduledWorkflowFQN := runtime .FuncForPC (reflect .ValueOf (simpleWorkflowWithSchedule ).Pointer ()).Name ()
4307+ require .Equal (t , scheduledWorkflowFQN , entry .FQN , "ScheduledWorkflow should have the correct FQN" )
4308+ require .Equal (t , "0 0 * * * *" , entry .CronSchedule , "ScheduledWorkflow should have the correct cron schedule" )
4309+ })
4310+ }
4311+
42414312func TestWorkflowIdentity (t * testing.T ) {
42424313 dbosCtx := setupDBOS (t , true , true )
42434314 RegisterWorkflow (dbosCtx , simpleWorkflow )
0 commit comments