Skip to content

Commit f53b648

Browse files
authored
Merge branch 'main' into runAsStep-inside-Go-routines
2 parents 2e25f77 + ec81187 commit f53b648

22 files changed

+889
-155
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ jobs:
6060
- name: Install gotestsum
6161
run: go install gotest.tools/gotestsum@latest
6262

63+
- name: Install mockery
64+
run: go install github.com/vektra/mockery/v3@latest
65+
66+
- name: Generate mocks
67+
run: go generate ./...
68+
working-directory: ./dbos
69+
6370
- name: Run tests
6471
run: go vet ./... && gotestsum --format github-action -- -race -v -count=1 ./...
6572
working-directory: ./dbos

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to DBOS Transact Python
1+
# Contributing to DBOS Transact Golang
22

33
Thank you for considering contributing to DBOS Transact. We welcome contributions from everyone, including bug fixes, feature enhancements, documentation improvements, or any other form of contribution.
44

cmd/dbos/cli_integration_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"database/sql"
7+
_ "embed"
78
"encoding/json"
89
"fmt"
910
"io"
@@ -17,11 +18,15 @@ import (
1718
"time"
1819

1920
"github.com/dbos-inc/dbos-transact-golang/dbos"
21+
"github.com/google/uuid"
2022
_ "github.com/jackc/pgx/v5/stdlib"
2123
"github.com/stretchr/testify/assert"
2224
"github.com/stretchr/testify/require"
2325
)
2426

27+
//go:embed cli_test_app.go.test
28+
var testAppContent []byte
29+
2530
// Test configuration
2631
const (
2732
testProjectName = "test-project"
@@ -49,6 +54,9 @@ func TestCLIWorkflow(t *testing.T) {
4954
// Build the CLI once at the beginning
5055
cliPath := buildCLI(t)
5156
t.Logf("Built CLI at: %s", cliPath)
57+
t.Cleanup(func() {
58+
os.Remove(cliPath)
59+
})
5260

5361
// Create temporary directory for test
5462
tempDir := t.TempDir()
@@ -142,12 +150,7 @@ func testProjectInitialization(t *testing.T, cliPath string) {
142150
require.NoError(t, err)
143151
assert.Contains(t, string(mainGoContent), testProjectName, "main.go should contain project name")
144152

145-
// Copy the test app to replace the template main.go
146-
testAppPath := filepath.Join(filepath.Dir(cliPath), "cli_test_app.go.test")
147-
testAppContent, err := os.ReadFile(testAppPath)
148-
require.NoError(t, err, "Failed to read test app: %s", testAppPath)
149-
150-
// Replace the template main.go with our test app
153+
// Replace the template main.go with our embedded test app
151154
mainGoPath := filepath.Join(projectDir, "main.go")
152155
err = os.WriteFile(mainGoPath, testAppContent, 0644)
153156
require.NoError(t, err, "Failed to write test app to main.go")
@@ -550,7 +553,9 @@ func testForkWorkflow(t *testing.T, cliPath string) {
550553
assert.NotEmpty(t, workflowID, "Workflow ID should not be empty")
551554

552555
t.Run("ForkWorkflow", func(t *testing.T) {
553-
cmd := exec.Command(cliPath, "workflow", "fork", workflowID)
556+
newID := uuid.NewString()
557+
targetVersion := "1.0.0"
558+
cmd := exec.Command(cliPath, "workflow", "fork", workflowID, "--forked-workflow-id", newID, "--application-version", targetVersion)
554559
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
555560

556561
output, err := cmd.CombinedOutput()
@@ -564,6 +569,8 @@ func testForkWorkflow(t *testing.T, cliPath string) {
564569
assert.NotEqual(t, workflowID, forkedStatus.ID, "Forked workflow should have different ID")
565570
assert.Equal(t, "ENQUEUED", string(forkedStatus.Status), "Forked workflow should be enqueued")
566571
assert.Equal(t, dbosInternalQueueName, forkedStatus.QueueName, "Should be on internal queue")
572+
assert.Equal(t, newID, forkedStatus.ID, "Forked workflow should have specified ID")
573+
assert.Equal(t, targetVersion, forkedStatus.ApplicationVersion, "Forked workflow should have specified application version")
567574
})
568575

569576
t.Run("ForkWorkflowFromStep", func(t *testing.T) {

cmd/dbos/init.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ var initCmd = &cobra.Command{
1616
RunE: runInit,
1717
}
1818

19-
var (
20-
configOnly bool
21-
)
22-
2319
type templateData struct {
2420
ProjectName string
2521
}

cmd/dbos/migrate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ func runMigrate(cmd *cobra.Command, args []string) error {
3333
return err
3434
}
3535

36+
ctx := context.Background()
37+
3638
// Create DBOS context which will run migrations automatically for the system DB
37-
_, err = createDBOSContext(dbURL)
39+
_, err = createDBOSContext(ctx, dbURL)
3840
if err != nil {
3941
return fmt.Errorf("failed to create DBOS context: %w", err)
4042
}

cmd/dbos/reset.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ var resetCmd = &cobra.Command{
1717

1818
var (
1919
skipConfirmation bool
20-
sysDBName string
2120
)
2221

2322
func init() {
2423
resetCmd.Flags().BoolVarP(&skipConfirmation, "yes", "y", false, "Skip confirmation prompt")
25-
resetCmd.Flags().StringVarP(&sysDBName, "sys-db-name", "s", "", "Specify the name of the system database to reset")
2624
}
2725

2826
func runReset(cmd *cobra.Command, args []string) error {

cmd/dbos/templates/dbos-toolbox/main.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func ScheduledWorkflow(ctx dbos.DBOSContext, scheduledTime time.Time) (string, e
9090
func main() {
9191
// Create DBOS context
9292
var err error
93-
dbosCtx, err = dbos.NewDBOSContext(dbos.Config{
93+
dbosCtx, err = dbos.NewDBOSContext(context.Background(), dbos.Config{
9494
DatabaseURL: os.Getenv("DBOS_SYSTEM_DATABASE_URL"),
9595
AppName: "{{.ProjectName}}",
9696
AdminServer: true,

cmd/dbos/utils.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"log/slog"
@@ -74,13 +75,14 @@ func getDBURL(_ *cobra.Command) (string, error) {
7475
}
7576

7677
// createDBOSContext creates a new DBOS context with the provided database URL
77-
func createDBOSContext(dbURL string) (dbos.DBOSContext, error) {
78+
func createDBOSContext(userContext context.Context, dbURL string) (dbos.DBOSContext, error) {
7879
appName := "dbos-cli"
7980

80-
ctx, err := dbos.NewDBOSContext(dbos.Config{
81+
ctx, err := dbos.NewDBOSContext(context.Background(), dbos.Config{
8182
DatabaseURL: dbURL,
8283
AppName: appName,
8384
Logger: initLogger(slog.LevelError),
85+
Context: userContext,
8486
})
8587
if err != nil {
8688
return nil, fmt.Errorf("failed to create DBOS context: %w", err)

cmd/dbos/workflow.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"time"
67

@@ -78,6 +79,8 @@ func init() {
7879

7980
// Fork command flags
8081
workflowForkCmd.Flags().IntP("step", "s", 1, "Restart from this step")
82+
workflowForkCmd.Flags().StringP("application-version", "a", "", "Application version for the forked workflow")
83+
workflowForkCmd.Flags().StringP("forked-workflow-id", "f", "", "Custom workflow ID for the forked workflow")
8184
}
8285

8386
func runWorkflowList(cmd *cobra.Command, args []string) error {
@@ -87,8 +90,10 @@ func runWorkflowList(cmd *cobra.Command, args []string) error {
8790
return err
8891
}
8992

93+
user_ctx := context.Background()
94+
9095
// Create DBOS context
91-
ctx, err := createDBOSContext(dbURL)
96+
ctx, err := createDBOSContext(user_ctx, dbURL)
9297
if err != nil {
9398
return err
9499
}
@@ -192,8 +197,10 @@ func runWorkflowGet(cmd *cobra.Command, args []string) error {
192197
return err
193198
}
194199

200+
user_ctx := context.Background()
201+
195202
// Create DBOS context
196-
ctx, err := createDBOSContext(dbURL)
203+
ctx, err := createDBOSContext(user_ctx, dbURL)
197204
if err != nil {
198205
return err
199206
}
@@ -225,8 +232,10 @@ func runWorkflowSteps(cmd *cobra.Command, args []string) error {
225232
return err
226233
}
227234

235+
user_ctx := context.Background()
236+
228237
// Create DBOS context
229-
ctx, err := createDBOSContext(dbURL)
238+
ctx, err := createDBOSContext(user_ctx, dbURL)
230239
if err != nil {
231240
return err
232241
}
@@ -255,8 +264,10 @@ func runWorkflowCancel(cmd *cobra.Command, args []string) error {
255264
return err
256265
}
257266

267+
user_ctx := context.Background()
268+
258269
// Create DBOS context
259-
ctx, err := createDBOSContext(dbURL)
270+
ctx, err := createDBOSContext(user_ctx, dbURL)
260271
if err != nil {
261272
return err
262273
}
@@ -279,8 +290,10 @@ func runWorkflowResume(cmd *cobra.Command, args []string) error {
279290
return err
280291
}
281292

293+
user_ctx := context.Background()
294+
282295
// Create DBOS context
283-
ctx, err := createDBOSContext(dbURL)
296+
ctx, err := createDBOSContext(user_ctx, dbURL)
284297
if err != nil {
285298
return err
286299
}
@@ -310,8 +323,10 @@ func runWorkflowFork(cmd *cobra.Command, args []string) error {
310323
return err
311324
}
312325

326+
user_ctx := context.Background()
327+
313328
// Create DBOS context
314-
ctx, err := createDBOSContext(dbURL)
329+
ctx, err := createDBOSContext(user_ctx, dbURL)
315330
if err != nil {
316331
return err
317332
}
@@ -322,11 +337,24 @@ func runWorkflowFork(cmd *cobra.Command, args []string) error {
322337
step = 1
323338
}
324339

325-
// Fork workflow
326-
handle, err := ctx.ForkWorkflow(ctx, dbos.ForkWorkflowInput{
340+
// Build ForkWorkflowInput
341+
input := dbos.ForkWorkflowInput{
327342
OriginalWorkflowID: workflowID,
328343
StartStep: uint(step),
329-
})
344+
}
345+
346+
// Get application version flag if provided
347+
if appVersion, _ := cmd.Flags().GetString("application-version"); appVersion != "" {
348+
input.ApplicationVersion = appVersion
349+
}
350+
351+
// Get forked workflow ID flag if provided
352+
if forkedID, _ := cmd.Flags().GetString("forked-workflow-id"); forkedID != "" {
353+
input.ForkedWorkflowID = forkedID
354+
}
355+
356+
// Fork workflow
357+
handle, err := ctx.ForkWorkflow(ctx, input)
330358
if err != nil {
331359
return err
332360
}

dbos/admin_server_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dbos
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -19,7 +20,7 @@ func TestAdminServer(t *testing.T) {
1920
databaseURL := getDatabaseURL()
2021

2122
t.Run("Admin server is not started by default", func(t *testing.T) {
22-
ctx, err := NewDBOSContext(Config{
23+
ctx, err := NewDBOSContext(context.Background(), Config{
2324
DatabaseURL: databaseURL,
2425
AppName: "test-app",
2526
})
@@ -50,7 +51,7 @@ func TestAdminServer(t *testing.T) {
5051
t.Run("Admin server endpoints", func(t *testing.T) {
5152
resetTestDatabase(t, databaseURL)
5253
// Launch DBOS with admin server once for all endpoint tests
53-
ctx, err := NewDBOSContext(Config{
54+
ctx, err := NewDBOSContext(context.Background(), Config{
5455
DatabaseURL: databaseURL,
5556
AppName: "test-app",
5657
AdminServer: true,
@@ -214,7 +215,7 @@ func TestAdminServer(t *testing.T) {
214215

215216
t.Run("List workflows input/output values", func(t *testing.T) {
216217
resetTestDatabase(t, databaseURL)
217-
ctx, err := NewDBOSContext(Config{
218+
ctx, err := NewDBOSContext(context.Background(), Config{
218219
DatabaseURL: databaseURL,
219220
AppName: "test-app",
220221
AdminServer: true,
@@ -361,7 +362,7 @@ func TestAdminServer(t *testing.T) {
361362

362363
t.Run("List endpoints time filtering", func(t *testing.T) {
363364
resetTestDatabase(t, databaseURL)
364-
ctx, err := NewDBOSContext(Config{
365+
ctx, err := NewDBOSContext(context.Background(), Config{
365366
DatabaseURL: databaseURL,
366367
AppName: "test-app",
367368
AdminServer: true,
@@ -535,7 +536,7 @@ func TestAdminServer(t *testing.T) {
535536

536537
t.Run("ListQueuedWorkflows", func(t *testing.T) {
537538
resetTestDatabase(t, databaseURL)
538-
ctx, err := NewDBOSContext(Config{
539+
ctx, err := NewDBOSContext(context.Background(), Config{
539540
DatabaseURL: databaseURL,
540541
AppName: "test-app",
541542
AdminServer: true,
@@ -721,7 +722,7 @@ func TestAdminServer(t *testing.T) {
721722

722723
t.Run("TestDeactivate", func(t *testing.T) {
723724
resetTestDatabase(t, databaseURL)
724-
ctx, err := NewDBOSContext(Config{
725+
ctx, err := NewDBOSContext(context.Background(), Config{
725726
DatabaseURL: databaseURL,
726727
AppName: "test-app",
727728
AdminServer: true,

0 commit comments

Comments
 (0)