From e816ecc5a0c9b0ccf8a2ea61fdb51f06fa70d24b Mon Sep 17 00:00:00 2001 From: maxdml Date: Mon, 29 Sep 2025 09:56:16 -0700 Subject: [PATCH] use new Launch/Shutdown package methods in tests --- chaos_tests/chaos_test.go | 10 +++++----- dbos/admin_server_test.go | 24 ++++++++++++------------ dbos/client_test.go | 10 +++++----- dbos/dbos_test.go | 30 +++++++++++++++--------------- dbos/logger_test.go | 8 ++++---- dbos/queues_test.go | 20 ++++++++++---------- dbos/utils_test.go | 2 +- dbos/workflows_test.go | 10 +++++----- integration/mocks_test.go | 4 ++-- 9 files changed, 59 insertions(+), 59 deletions(-) diff --git a/chaos_tests/chaos_test.go b/chaos_tests/chaos_test.go index e23c2b6f..bc1d0cd0 100644 --- a/chaos_tests/chaos_test.go +++ b/chaos_tests/chaos_test.go @@ -188,7 +188,7 @@ func setupDBOS(t *testing.T) dbos.DBOSContext { // Register cleanup to run after test completes t.Cleanup(func() { if dbosCtx != nil { - dbosCtx.Shutdown(30 * time.Second) + dbos.Shutdown(dbosCtx, 30*time.Second) } }) @@ -246,7 +246,7 @@ func TestChaosWorkflow(t *testing.T) { // Register scheduled workflow to run every second for chaos testing dbos.RegisterWorkflow(dbosCtx, scheduledWorkflow, dbos.WithSchedule("* * * * * *"), dbos.WithWorkflowName("ScheduledChaosTest")) - err := dbosCtx.Launch() + err := dbos.Launch(dbosCtx) require.NoError(t, err) // Run multiple workflows @@ -309,7 +309,7 @@ func TestChaosRecv(t *testing.T) { // Register the workflow dbos.RegisterWorkflow(dbosCtx, recvWorkflow) - err := dbosCtx.Launch() + err := dbos.Launch(dbosCtx) require.NoError(t, err) // Run multiple workflows with send/recv @@ -364,7 +364,7 @@ func TestChaosEvents(t *testing.T) { // Register the workflow dbos.RegisterWorkflow(dbosCtx, eventWorkflow) - err := dbosCtx.Launch() + err := dbos.Launch(dbosCtx) require.NoError(t, err) // Run multiple workflows with events @@ -455,7 +455,7 @@ func TestChaosQueues(t *testing.T) { dbos.RegisterWorkflow(dbosCtx, stepTwo) dbos.RegisterWorkflow(dbosCtx, workflow) - err := dbosCtx.Launch() + err := dbos.Launch(dbosCtx) require.NoError(t, err) // Run multiple workflows diff --git a/dbos/admin_server_test.go b/dbos/admin_server_test.go index c70f770f..e9fb6c35 100644 --- a/dbos/admin_server_test.go +++ b/dbos/admin_server_test.go @@ -32,12 +32,12 @@ func TestAdminServer(t *testing.T) { }) require.NoError(t, err) - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) // Ensure cleanup defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -65,13 +65,13 @@ func TestAdminServer(t *testing.T) { }) require.NoError(t, err) - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) // Ensure cleanup defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -253,13 +253,13 @@ func TestAdminServer(t *testing.T) { } RegisterWorkflow(ctx, structWorkflow) - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) // Ensure cleanup defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -381,13 +381,13 @@ func TestAdminServer(t *testing.T) { } RegisterWorkflow(ctx, testWorkflow) - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) // Ensure cleanup defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -569,14 +569,14 @@ func TestAdminServer(t *testing.T) { } RegisterWorkflow(ctx, regularWorkflow) - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) // Ensure cleanup defer func() { close(blockingChan) // Unblock any blocked workflows if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -745,7 +745,7 @@ func TestAdminServer(t *testing.T) { return fmt.Sprintf("executed at %v", scheduledTime), nil }, WithSchedule("* * * * * *")) // Every second - err = ctx.Launch() + err = Launch(ctx) require.NoError(t, err) client := &http.Client{Timeout: 5 * time.Second} @@ -753,7 +753,7 @@ func TestAdminServer(t *testing.T) { // Ensure cleanup defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } if client.Transport != nil { client.Transport.(*http.Transport).CloseIdleConnections() diff --git a/dbos/client_test.go b/dbos/client_test.go index be014330..ab4d287a 100644 --- a/dbos/client_test.go +++ b/dbos/client_test.go @@ -60,7 +60,7 @@ func TestEnqueue(t *testing.T) { RegisterWorkflow(serverCtx, priorityWorkflow, WithWorkflowName("PriorityWorkflow")) // Launch the server context to start processing tasks - err := serverCtx.Launch() + err := Launch(serverCtx) require.NoError(t, err) // Setup client - this will enqueue tasks @@ -319,7 +319,7 @@ func TestCancelResume(t *testing.T) { RegisterWorkflow(serverCtx, timeoutBlockingWorkflow, WithWorkflowName("TimeoutBlockingWorkflow")) // Launch the server context to start processing tasks - err := serverCtx.Launch() + err := Launch(serverCtx) require.NoError(t, err) // Setup client - this will enqueue tasks @@ -570,7 +570,7 @@ func TestForkWorkflow(t *testing.T) { RegisterWorkflow(serverCtx, parentWorkflow, WithWorkflowName("ParentWorkflow")) // Launch the server context to start processing tasks - err := serverCtx.Launch() + err := Launch(serverCtx) require.NoError(t, err) // Setup client @@ -706,7 +706,7 @@ func TestListWorkflows(t *testing.T) { // Register cleanup for server context t.Cleanup(func() { if serverCtx != nil { - serverCtx.Shutdown(30 * time.Second) + Shutdown(serverCtx, 30*time.Second) } }) @@ -728,7 +728,7 @@ func TestListWorkflows(t *testing.T) { RegisterWorkflow(serverCtx, simpleWorkflow, WithWorkflowName("SimpleWorkflow")) // Launch server - err = serverCtx.Launch() + err = Launch(serverCtx) require.NoError(t, err) // Setup client with same custom schema diff --git a/dbos/dbos_test.go b/dbos/dbos_test.go index e924aff5..9e7a8c91 100644 --- a/dbos/dbos_test.go +++ b/dbos/dbos_test.go @@ -33,7 +33,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() // Clean up executor @@ -100,7 +100,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -121,7 +121,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -143,7 +143,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -168,7 +168,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -190,7 +190,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -262,7 +262,7 @@ func TestConfig(t *testing.T) { assert.Equal(t, int64(1), version, "migration version should be 1 (after initial migration)") // Test manual shutdown and recreate - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) // Recreate context - should have no error since DB is already migrated ctx2, err := NewDBOSContext(context.Background(), Config{ @@ -272,7 +272,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer func() { if ctx2 != nil { - ctx2.Shutdown(1 * time.Minute) + Shutdown(ctx2, 1*time.Minute) } }() @@ -301,7 +301,7 @@ func TestCustomSystemDBSchema(t *testing.T) { require.NoError(t, err) defer func() { if ctx != nil { - ctx.Shutdown(1 * time.Minute) + Shutdown(ctx, 1*time.Minute) } }() @@ -425,7 +425,7 @@ func TestCustomSystemDBSchema(t *testing.T) { RegisterWorkflow(ctx, recvSetEventWorkflow) // Launch the DBOS context - ctx.Launch() + Launch(ctx) // Test RunWorkflow - start both workflows that will communicate with each other workflowAID := uuid.NewString() @@ -548,7 +548,7 @@ func TestCustomPool(t *testing.T) { require.NotNil(t, customdbosContext) dbosCtx, ok := customdbosContext.(*dbosContext) - defer dbosCtx.Shutdown(10 * time.Second) + defer Shutdown(dbosCtx, 10*time.Second) require.True(t, ok) sysDB, ok := dbosCtx.systemDB.(*sysDB) @@ -570,9 +570,9 @@ func TestCustomPool(t *testing.T) { RegisterWorkflow(customdbosContext, recvSetEventWorkflowCustom) // Launch the DBOS context - err = customdbosContext.Launch() + err = Launch(customdbosContext) require.NoError(t, err) - defer dbosCtx.Shutdown(1 * time.Minute) + defer Shutdown(dbosCtx, 1*time.Minute) // Test RunWorkflow - start both workflows that will communicate with each other workflowAID := uuid.NewString() @@ -643,9 +643,9 @@ func TestCustomPool(t *testing.T) { RegisterWorkflow(dbosCtx, wf) // Launch the DBOS context - err = dbosCtx.Launch() + err = Launch(dbosCtx) require.NoError(t, err) - defer dbosCtx.Shutdown(1 * time.Minute) + defer Shutdown(dbosCtx, 1*time.Minute) // Run a workflow _, err = RunWorkflow(dbosCtx, wf, "test-input") diff --git a/dbos/logger_test.go b/dbos/logger_test.go index 78e3f379..92102eb1 100644 --- a/dbos/logger_test.go +++ b/dbos/logger_test.go @@ -26,11 +26,11 @@ func TestLogger(t *testing.T) { AppName: "test-app", }) // Create executor with default logger require.NoError(t, err) - err = dbosCtx.Launch() + err = Launch(dbosCtx) require.NoError(t, err) t.Cleanup(func() { if dbosCtx != nil { - dbosCtx.Shutdown(10 * time.Second) + Shutdown(dbosCtx, 10*time.Second) } }) @@ -59,11 +59,11 @@ func TestLogger(t *testing.T) { Logger: slogLogger, }) require.NoError(t, err) - err = dbosCtx.Launch() + err = Launch(dbosCtx) require.NoError(t, err) t.Cleanup(func() { if dbosCtx != nil { - dbosCtx.Shutdown(10 * time.Second) + Shutdown(dbosCtx, 10*time.Second) } }) diff --git a/dbos/queues_test.go b/dbos/queues_test.go index aa8077a8..0cc50867 100644 --- a/dbos/queues_test.go +++ b/dbos/queues_test.go @@ -158,7 +158,7 @@ func TestWorkflowQueues(t *testing.T) { } RegisterWorkflow(dbosCtx, workflowEnqueuesAnother) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err) t.Run("EnqueueWorkflow", func(t *testing.T) { @@ -502,7 +502,7 @@ func TestQueueRecovery(t *testing.T) { } RegisterWorkflow(dbosCtx, recoveryWorkflowFunc) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS instance") queuedSteps := 5 @@ -588,7 +588,7 @@ func TestGlobalConcurrency(t *testing.T) { } RegisterWorkflow(dbosCtx, globalConcurrencyWorkflowFunc) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS instance") // Enqueue two workflows @@ -686,10 +686,10 @@ func TestWorkerConcurrency(t *testing.T) { RegisterWorkflow(dbosCtx1, blockingWfFunc) RegisterWorkflow(dbosCtx2, blockingWfFunc) - err := dbosCtx1.Launch() + err := Launch(dbosCtx1) require.NoError(t, err, "failed to launch DBOS instance") - err = dbosCtx2.Launch() + err = Launch(dbosCtx2) require.NoError(t, err, "failed to launch DBOS instance") // First enqueue four blocking workflows @@ -764,7 +764,7 @@ func TestWorkerConcurrencyXRecovery(t *testing.T) { } RegisterWorkflow(dbosCtx, workerConcurrencyRecoveryBlockingWf2) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS instance") // Enqueue two workflows on a queue with worker concurrency = 1 @@ -838,7 +838,7 @@ func TestQueueRateLimiter(t *testing.T) { // Create workflow with dbosContext RegisterWorkflow(dbosCtx, rateLimiterTestWorkflow) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS instance") limit := 5 @@ -982,7 +982,7 @@ func TestQueueTimeouts(t *testing.T) { } RegisterWorkflow(dbosCtx, fastWorkflow) - dbosCtx.Launch() + Launch(dbosCtx) t.Run("EnqueueWorkflowTimeout", func(t *testing.T) { // Start a workflow that will wait indefinitely @@ -1171,7 +1171,7 @@ func TestPriorityQueue(t *testing.T) { } RegisterWorkflow(dbosCtx, testWorkflow) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err) var wfHandles []WorkflowHandle[int] @@ -1255,7 +1255,7 @@ func TestListQueuedWorkflows(t *testing.T) { testQueue1 := NewWorkflowQueue(dbosCtx, "list-test-queue", WithGlobalConcurrency(1)) testQueue2 := NewWorkflowQueue(dbosCtx, "list-test-queue2", WithGlobalConcurrency(1)) - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS") t.Run("WithQueuesOnly", func(t *testing.T) { diff --git a/dbos/utils_test.go b/dbos/utils_test.go index 4009675c..54f8f5e9 100644 --- a/dbos/utils_test.go +++ b/dbos/utils_test.go @@ -69,7 +69,7 @@ func setupDBOS(t *testing.T, dropDB bool, checkLeaks bool) DBOSContext { t.Cleanup(func() { dbosCtx.(*dbosContext).logger.Info("Cleaning up DBOS instance...") if dbosCtx != nil { - dbosCtx.Shutdown(30 * time.Second) // Wait for workflows to finish and shutdown admin server and system database + Shutdown(dbosCtx, 30*time.Second) // Wait for workflows to finish and shutdown admin server and system database } dbosCtx = nil if checkLeaks { diff --git a/dbos/workflows_test.go b/dbos/workflows_test.go index dcc0d7e5..73eeb547 100644 --- a/dbos/workflows_test.go +++ b/dbos/workflows_test.go @@ -341,9 +341,9 @@ func TestWorkflowsRegistration(t *testing.T) { freshCtx := setupDBOS(t, false, true) // Don't reset DB but do check for leaks // Launch DBOS context - err := freshCtx.Launch() + err := Launch(freshCtx) require.NoError(t, err) - defer freshCtx.Shutdown(10 * time.Second) + defer Shutdown(freshCtx, 10*time.Second) // Attempting to register after launch should panic defer func() { @@ -1289,7 +1289,7 @@ func TestScheduledWorkflows(t *testing.T) { return fmt.Sprintf("Scheduled workflow scheduled at time %v and executed at time %v", scheduledTime, startTime), nil }, WithSchedule("* * * * * *")) // Every second - err := dbosCtx.Launch() + err := Launch(dbosCtx) require.NoError(t, err, "failed to launch DBOS") // Helper function to collect execution times @@ -1501,7 +1501,7 @@ func TestSendRecv(t *testing.T) { RegisterWorkflow(dbosCtx, workflowThatCallsSendInStep) RegisterWorkflow(dbosCtx, recvContextCancelWorkflow) - dbosCtx.Launch() + Launch(dbosCtx) t.Run("SendRecvSuccess", func(t *testing.T) { // Start the receive workflow @@ -2145,7 +2145,7 @@ func TestSetGetEvent(t *testing.T) { RegisterWorkflow(dbosCtx, getEventIdempotencyWorkflow) RegisterWorkflow(dbosCtx, durableGetEventSleepWorkflow) - dbosCtx.Launch() + Launch(dbosCtx) t.Run("SetGetEventFromWorkflow", func(t *testing.T) { // Clear the signal event before starting diff --git a/integration/mocks_test.go b/integration/mocks_test.go index eb7347fe..d9338768 100644 --- a/integration/mocks_test.go +++ b/integration/mocks_test.go @@ -126,11 +126,11 @@ func aRealProgramFunction(dbosCtx dbos.DBOSContext) error { dbos.RegisterWorkflow(dbosCtx, workflow) - err := dbosCtx.Launch() + err := dbos.Launch(dbosCtx) if err != nil { return err } - defer dbosCtx.Shutdown(1 * time.Second) + defer dbos.Shutdown(dbosCtx, 1*time.Second) res, err := workflow(dbosCtx, 2) if err != nil {