|
46 | 46 | wfClose = WithWorkflow(func(ctx context.Context, in string) (string, error) { |
47 | 47 | return prefix + in, nil |
48 | 48 | }) |
49 | | - // Workflow for idempotency testing |
50 | | - idempotencyWf = WithWorkflow(idempotencyWorkflow) |
51 | | - idempotencyWfWithStep = WithWorkflow(idempotencyWorkflowWithStep) |
52 | 49 | ) |
53 | 50 |
|
54 | 51 | func simpleWorkflow(ctxt context.Context, input string) (string, error) { |
@@ -81,27 +78,6 @@ func incrementCounter(_ context.Context, value int64) (int64, error) { |
81 | 78 | return idempotencyCounter, nil |
82 | 79 | } |
83 | 80 |
|
84 | | -func idempotencyWorkflow(ctx context.Context, input string) (string, error) { |
85 | | - incrementCounter(ctx, 1) |
86 | | - return input, nil |
87 | | -} |
88 | | - |
89 | | -var blockingStepStopEvent *Event |
90 | | - |
91 | | -func blockingStep(ctx context.Context, input string) (string, error) { |
92 | | - blockingStepStopEvent.Wait() |
93 | | - return "", nil |
94 | | -} |
95 | | - |
96 | | -var idempotencyWorkflowWithStepEvent *Event |
97 | | - |
98 | | -func idempotencyWorkflowWithStep(ctx context.Context, input string) (int64, error) { |
99 | | - RunAsStep(ctx, incrementCounter, 1) |
100 | | - idempotencyWorkflowWithStepEvent.Set() |
101 | | - RunAsStep(ctx, blockingStep, input) |
102 | | - return idempotencyCounter, nil |
103 | | -} |
104 | | - |
105 | 81 | // Unified struct that demonstrates both pointer and value receiver methods |
106 | 82 | type workflowStruct struct{} |
107 | 83 |
|
@@ -139,7 +115,6 @@ var ( |
139 | 115 | }) |
140 | 116 | ) |
141 | 117 |
|
142 | | -// TODO: spin into dbos_test.go |
143 | 118 | func TestAppVersion(t *testing.T) { |
144 | 119 | if _, err := hex.DecodeString(APP_VERSION); err != nil { |
145 | 120 | t.Fatalf("APP_VERSION is not a valid hex string: %v", err) |
@@ -589,6 +564,32 @@ func TestChildWorkflow(t *testing.T) { |
589 | 564 | }) |
590 | 565 | } |
591 | 566 |
|
| 567 | +var ( |
| 568 | + idempotencyWf = WithWorkflow(idempotencyWorkflow) |
| 569 | + idempotencyWfWithStep = WithWorkflow(idempotencyWorkflowWithStep) |
| 570 | +) |
| 571 | + |
| 572 | +func idempotencyWorkflow(ctx context.Context, input string) (string, error) { |
| 573 | + incrementCounter(ctx, 1) |
| 574 | + return input, nil |
| 575 | +} |
| 576 | + |
| 577 | +var blockingStepStopEvent *Event |
| 578 | + |
| 579 | +func blockingStep(ctx context.Context, input string) (string, error) { |
| 580 | + blockingStepStopEvent.Wait() |
| 581 | + return "", nil |
| 582 | +} |
| 583 | + |
| 584 | +var idempotencyWorkflowWithStepEvent *Event |
| 585 | + |
| 586 | +func idempotencyWorkflowWithStep(ctx context.Context, input string) (int64, error) { |
| 587 | + RunAsStep(ctx, incrementCounter, 1) |
| 588 | + idempotencyWorkflowWithStepEvent.Set() |
| 589 | + RunAsStep(ctx, blockingStep, input) |
| 590 | + return idempotencyCounter, nil |
| 591 | +} |
| 592 | + |
592 | 593 | func TestWorkflowIdempotency(t *testing.T) { |
593 | 594 | setupDBOS(t) |
594 | 595 |
|
@@ -639,9 +640,7 @@ func TestWorkflowIdempotency(t *testing.T) { |
639 | 640 |
|
640 | 641 | func TestWorkflowRecovery(t *testing.T) { |
641 | 642 | setupDBOS(t) |
642 | | - |
643 | 643 | t.Run("RecoveryResumeWhereItLeftOff", func(t *testing.T) { |
644 | | - |
645 | 644 | // Reset the global counter |
646 | 645 | idempotencyCounter = 0 |
647 | 646 |
|
@@ -713,7 +712,6 @@ func TestWorkflowRecovery(t *testing.T) { |
713 | 712 | if result != idempotencyCounter { |
714 | 713 | t.Fatalf("expected result to be %s, got %s", input, result) |
715 | 714 | } |
716 | | - |
717 | 715 | }) |
718 | 716 | } |
719 | 717 |
|
|
0 commit comments