Skip to content

Commit e9d5c4f

Browse files
committed
fix test + nits
1 parent a9a83a1 commit e9d5c4f

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

dbos/queues_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,18 @@ func TestWorkflowQueues(t *testing.T) {
265265
workflowID := "conflicting-workflow-id"
266266

267267
// Enqueue the same workflow ID on the first queue
268-
handle1, err := RunAsWorkflow(dbosCtx, queueWorkflow, "test-input-1", WithQueue(conflictQueue1.Name), WithWorkflowID(workflowID))
268+
handle, err := RunAsWorkflow(dbosCtx, queueWorkflow, "test-input-1", WithQueue(conflictQueue1.Name), WithWorkflowID(workflowID))
269269
if err != nil {
270270
t.Fatalf("failed to enqueue workflow on first queue: %v", err)
271271
}
272272

273273
// Get the result from the first workflow to ensure it completes
274-
result1, err := handle1.GetResult()
274+
result, err := handle.GetResult()
275275
if err != nil {
276276
t.Fatalf("failed to get result from first workflow: %v", err)
277277
}
278-
if result1 != "test-input-1" {
279-
t.Fatalf("expected 'test-input-1', got %v", result1)
278+
if result != "test-input-1" {
279+
t.Fatalf("expected 'test-input-1', got %v", result)
280280
}
281281

282282
// Now try to enqueue the same workflow ID on a different queue

dbos/workflows_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ func simpleStep(_ context.Context) (string, error) {
4444
return "from step", nil
4545
}
4646

47-
func concurrentSimpleWorkflow(dbosCtx DBOSContext, input int) (int, error) {
48-
return RunAsStep(dbosCtx, func(ctx context.Context) (int, error) {
49-
return input * 2, nil
50-
})
51-
}
52-
5347
func simpleStepError(_ context.Context) (string, error) {
5448
return "", fmt.Errorf("step failure")
5549
}
@@ -808,8 +802,6 @@ func TestChildWorkflow(t *testing.T) {
808802

809803
// Simple child workflow that returns a result
810804
pollingHandleChildWf := func(dbosCtx DBOSContext, input string) (string, error) {
811-
// Signal the child workflow is started
812-
pollingHandleStartEvent.Set()
813805
// Wait
814806
pollingHandleCompleteEvent.Wait()
815807
return input + "-result", nil
@@ -840,6 +832,9 @@ func TestChildWorkflow(t *testing.T) {
840832
}
841833
}
842834

835+
// Signal the child workflow is started
836+
pollingHandleStartEvent.Set()
837+
843838
result, err := childHandle.GetResult()
844839
if err != nil {
845840
return "", fmt.Errorf("failed to get result from child workflow: %w", err)
@@ -854,7 +849,7 @@ func TestChildWorkflow(t *testing.T) {
854849
t.Fatalf("failed to start parent workflow: %v", err)
855850
}
856851

857-
// Wait for the child workflow to start
852+
// Wait for the workflows to start
858853
pollingHandleStartEvent.Wait()
859854

860855
// Recover pending workflows - this should give us both parent and child handles
@@ -3056,6 +3051,12 @@ func sendRecvSenderWorkflow(ctx DBOSContext, pairID int) (string, error) {
30563051
return "message-sent", nil
30573052
}
30583053

3054+
func concurrentSimpleWorkflow(dbosCtx DBOSContext, input int) (int, error) {
3055+
return RunAsStep(dbosCtx, func(ctx context.Context) (int, error) {
3056+
return input * 2, nil
3057+
})
3058+
}
3059+
30593060
func TestConcurrentWorkflows(t *testing.T) {
30603061
dbosCtx := setupDBOS(t, true, true)
30613062
RegisterWorkflow(dbosCtx, concurrentSimpleWorkflow)
@@ -3084,6 +3085,11 @@ func TestConcurrentWorkflows(t *testing.T) {
30843085
errors <- fmt.Errorf("failed to get result for workflow %d: %w", input, err)
30853086
return
30863087
}
3088+
expectedResult := input * 2
3089+
if result != expectedResult {
3090+
errors <- fmt.Errorf("workflow %d: expected result %d, got %d", input, expectedResult, result)
3091+
return
3092+
}
30873093
results <- result
30883094
}(i)
30893095
}
@@ -3113,13 +3119,6 @@ func TestConcurrentWorkflows(t *testing.T) {
31133119
if resultCount != numGoroutines {
31143120
t.Fatalf("Expected %d results, got %d", numGoroutines, resultCount)
31153121
}
3116-
3117-
for i := range numGoroutines {
3118-
expectedResult := i * 2
3119-
if !receivedResults[expectedResult] {
3120-
t.Errorf("Expected result %d not found", expectedResult)
3121-
}
3122-
}
31233122
})
31243123

31253124
t.Run("NotificationWorkflows", func(t *testing.T) {

0 commit comments

Comments
 (0)