Skip to content

Commit acd9736

Browse files
committed
Organize tests
1 parent 23a3052 commit acd9736

File tree

6 files changed

+169
-219
lines changed

6 files changed

+169
-219
lines changed

backend/test/e2e.go

Lines changed: 8 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
223223
},
224224
},
225225
{
226-
name: "SubWorkflow_Simple",
226+
name: "SubWorkflow/Simple",
227227
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
228228
swf := func(ctx workflow.Context, i int) (int, error) {
229229
return i * 2, nil
@@ -246,7 +246,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
246246
},
247247
},
248248
{
249-
name: "SubWorkflow_DuplicateActiveInstanceID",
249+
name: "SubWorkflow/DuplicateActiveInstanceID",
250250
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
251251
swf := func(ctx workflow.Context, i int) (int, error) {
252252
workflow.NewSignalChannel[any](ctx, "signal").Receive(ctx)
@@ -285,7 +285,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
285285
},
286286
},
287287
{
288-
name: "SubWorkflow_DuplicateInactiveInstanceID",
288+
name: "SubWorkflow/DuplicateInactiveInstanceID",
289289
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
290290
swf := func(ctx workflow.Context, i int) (int, error) {
291291
return i * 2, nil
@@ -319,7 +319,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
319319
},
320320
},
321321
{
322-
name: "SubWorkflow_PropagateCancellation",
322+
name: "SubWorkflow/PropagateCancellation",
323323
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
324324
canceled := int32(0)
325325

@@ -383,7 +383,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
383383
},
384384
},
385385
{
386-
name: "SubWorkflow_CancelBeforeStarting",
386+
name: "SubWorkflow/CancelBeforeStarting",
387387
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
388388
swInstanceID := "subworkflow"
389389

@@ -429,7 +429,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
429429
},
430430
},
431431
{
432-
name: "SubWorkflow_Signal",
432+
name: "SubWorkflow/Signal",
433433
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
434434
swf := func(ctx workflow.Context, i int) (int, error) {
435435
workflow.NewSignalChannel[string](ctx, "signal").Receive(ctx)
@@ -463,7 +463,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
463463
},
464464
},
465465
{
466-
name: "SubWorkflow_DifferentQueue",
466+
name: "SubWorkflow/DifferentQueue",
467467
customWorkerOptions: func(options *worker.Options) {
468468
options.WorkflowQueues = []core.Queue{workflow.QueueDefault, workflow.Queue("custom")}
469469
},
@@ -502,7 +502,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
502502
},
503503
},
504504
{
505-
name: "SubWorkflow_Signal_BeforeStarting",
505+
name: "SubWorkflow/Signal_BeforeStarting",
506506
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
507507
wf := func(ctx workflow.Context) (int, error) {
508508
id, _ := workflow.SideEffect(ctx, func(ctx workflow.Context) string {
@@ -525,157 +525,6 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
525525
require.ErrorContains(t, err, backend.ErrInstanceNotFound.Error())
526526
},
527527
},
528-
{
529-
name: "Timer_CancelWorkflowInstance",
530-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
531-
a := func(ctx context.Context) error {
532-
return nil
533-
}
534-
wf := func(ctx workflow.Context) error {
535-
_, err := workflow.ScheduleTimer(ctx, time.Second*10).Get(ctx)
536-
if err != nil && err != workflow.Canceled {
537-
return err
538-
}
539-
540-
return nil
541-
}
542-
register(t, ctx, w, []interface{}{wf}, []interface{}{a})
543-
544-
instance := runWorkflow(t, ctx, c, wf)
545-
546-
// Allow some time for the timer to get scheduled
547-
time.Sleep(time.Millisecond * 200)
548-
549-
require.NoError(t, c.CancelWorkflowInstance(ctx, instance))
550-
551-
_, err := client.GetWorkflowResult[any](ctx, c, instance, time.Second*5)
552-
require.NoError(t, err)
553-
},
554-
},
555-
{
556-
name: "Timer_CancelBeforeStarting",
557-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
558-
a := func(ctx context.Context) error {
559-
return nil
560-
}
561-
wf := func(ctx workflow.Context) error {
562-
tctx, cancel := workflow.WithCancel(ctx)
563-
564-
f := workflow.ScheduleTimer(tctx, time.Second*10)
565-
566-
// Cancel before it can be started
567-
cancel()
568-
569-
// Force the checkpoint before continuing the execution
570-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
571-
572-
_, err := f.Get(ctx)
573-
if err != nil && err != workflow.Canceled {
574-
return err
575-
}
576-
577-
return nil
578-
}
579-
register(t, ctx, w, []interface{}{wf}, []interface{}{a})
580-
581-
instance := runWorkflow(t, ctx, c, wf)
582-
_, err := client.GetWorkflowResult[any](ctx, c, instance, time.Second*5)
583-
require.NoError(t, err)
584-
585-
events, err := b.GetWorkflowInstanceHistory(ctx, instance, nil)
586-
require.NoError(t, err)
587-
for _, e := range events {
588-
if e.Type == history.EventType_TimerScheduled {
589-
require.FailNow(t, "timer should not be scheduled")
590-
}
591-
}
592-
593-
futureEvents, err := b.GetFutureEvents(ctx)
594-
require.NoError(t, err)
595-
require.Len(t, futureEvents, 0, "no future events should be scheduled")
596-
},
597-
},
598-
{
599-
name: "Timer_CancelTwice",
600-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
601-
a := func(ctx context.Context) error {
602-
return nil
603-
}
604-
wf := func(ctx workflow.Context) error {
605-
tctx, cancel := workflow.WithCancel(ctx)
606-
f := workflow.ScheduleTimer(tctx, time.Second*10)
607-
608-
// Force the checkpoint before continuing the execution
609-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
610-
611-
// Cancel timer
612-
cancel()
613-
614-
// Force another checkpoint
615-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
616-
617-
cancel()
618-
619-
// Force another checkpoint
620-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
621-
622-
if _, err := f.Get(ctx); err != nil && err != workflow.Canceled {
623-
return err
624-
}
625-
626-
return nil
627-
}
628-
register(t, ctx, w, []interface{}{wf}, []interface{}{a})
629-
630-
instance := runWorkflow(t, ctx, c, wf)
631-
_, err := client.GetWorkflowResult[any](ctx, c, instance, time.Second*5)
632-
require.NoError(t, err)
633-
634-
historyContains(ctx, t, b, instance, history.EventType_TimerScheduled, history.EventType_TimerCanceled)
635-
636-
futureEvents, err := b.GetFutureEvents(ctx)
637-
require.NoError(t, err)
638-
require.Len(t, futureEvents, 0, "no future events should be scheduled")
639-
},
640-
},
641-
{
642-
name: "Timer_CancelBeforeFiringRemovesFutureEvent",
643-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
644-
a := func(ctx context.Context) error {
645-
return nil
646-
}
647-
wf := func(ctx workflow.Context) error {
648-
tctx, cancel := workflow.WithCancel(ctx)
649-
f := workflow.ScheduleTimer(tctx, time.Second*10)
650-
651-
// Force the checkpoint before continuing the execution
652-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
653-
654-
// Cancel timer
655-
cancel()
656-
657-
// Force another checkpoint
658-
workflow.ExecuteActivity[any](ctx, workflow.DefaultActivityOptions, a).Get(ctx)
659-
660-
if _, err := f.Get(ctx); err != nil && err != workflow.Canceled {
661-
return err
662-
}
663-
664-
return nil
665-
}
666-
register(t, ctx, w, []interface{}{wf}, []interface{}{a})
667-
668-
instance := runWorkflow(t, ctx, c, wf)
669-
_, err := client.GetWorkflowResult[any](ctx, c, instance, time.Second*5)
670-
require.NoError(t, err)
671-
672-
historyContains(ctx, t, b, instance, history.EventType_TimerScheduled, history.EventType_TimerCanceled)
673-
674-
futureEvents, err := b.GetFutureEvents(ctx)
675-
require.NoError(t, err)
676-
require.Len(t, futureEvents, 0, "no future events should be scheduled")
677-
},
678-
},
679528
{
680529
name: "NonDeterminism",
681530
withoutCache: true,
@@ -764,57 +613,6 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
764613
require.Equal(t, "hello-23", r)
765614
},
766615
},
767-
{
768-
name: "ContinueAsNew",
769-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
770-
wf := func(ctx workflow.Context, run int) (int, error) {
771-
run = run + 1
772-
if run < 3 {
773-
return run, workflow.ContinueAsNew(ctx, run)
774-
}
775-
776-
return run, nil
777-
}
778-
register(t, ctx, w, []interface{}{wf}, nil)
779-
780-
instance := runWorkflow(t, ctx, c, wf, 0)
781-
782-
r, err := client.GetWorkflowResult[int](ctx, c, instance, time.Second*10)
783-
require.NoError(t, err)
784-
require.Equal(t, 1, r)
785-
786-
state, err := b.GetWorkflowInstanceState(ctx, instance)
787-
require.NoError(t, err)
788-
require.Equal(t, core.WorkflowInstanceStateContinuedAsNew, state)
789-
},
790-
},
791-
{
792-
name: "ContinueAsNew_Subworkflow",
793-
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
794-
swf := func(ctx workflow.Context, run int) (int, error) {
795-
l := workflow.Logger(ctx)
796-
797-
run = run + 1
798-
if run < 3 {
799-
l.Debug("continue as new", "run", run)
800-
return run, workflow.ContinueAsNew(ctx, run)
801-
}
802-
803-
return run, nil
804-
}
805-
806-
wf := func(ctx workflow.Context, run int) (int, error) {
807-
return workflow.CreateSubWorkflowInstance[int](ctx, workflow.DefaultSubWorkflowOptions, swf, run).Get(ctx)
808-
}
809-
register(t, ctx, w, []interface{}{wf, swf}, nil)
810-
811-
instance := runWorkflow(t, ctx, c, wf, 0)
812-
813-
r, err := client.GetWorkflowResult[int](ctx, c, instance, time.Second*20)
814-
require.NoError(t, err)
815-
require.Equal(t, 3, r)
816-
},
817-
},
818616
}
819617

820618
tests = append(tests, e2eActivityTests...)

backend/test/e2e_activity.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (e *CustomError) Error() string {
2323

2424
var e2eActivityTests = []backendTest{
2525
{
26-
name: "Activity_Panic",
26+
name: "Activity/Panic",
2727
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
2828
a := func(context.Context) error {
2929
panic("activity panic")
@@ -48,7 +48,7 @@ var e2eActivityTests = []backendTest{
4848
},
4949
},
5050
{
51-
name: "Activity_CustomError",
51+
name: "Activity/CustomError",
5252
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
5353
a := func(context.Context) error {
5454
return &CustomError{msg: "custom error"}
@@ -77,7 +77,7 @@ var e2eActivityTests = []backendTest{
7777
},
7878
},
7979
{
80-
name: "Activity_ReceiveAttempt",
80+
name: "Activity/ReceiveAttempt",
8181
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
8282
var maxAttempt int
8383

@@ -110,7 +110,7 @@ var e2eActivityTests = []backendTest{
110110
},
111111
},
112112
{
113-
name: "Activity_ExtendTask",
113+
name: "Activity/ExtendTask",
114114
customWorkerOptions: func(w *worker.Options) {
115115
w.ActivityHeartbeatInterval = 1 * time.Millisecond
116116
},

backend/test/e2e_diag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var e2eDiagTests = []backendTest{
1616
{
17-
name: "Diag_Paging",
17+
name: "Diag/Paging",
1818
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
1919
diagBackend, ok := b.(diag.Backend)
2020
if !ok {
@@ -52,7 +52,7 @@ var e2eDiagTests = []backendTest{
5252
},
5353
},
5454
{
55-
name: "Diag_GetWorkflowInstance_ReturnsQueue",
55+
name: "Diag/GetWorkflowInstance_ReturnsQueue",
5656
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
5757
diagBackend, ok := b.(diag.Backend)
5858
if !ok {

backend/test/e2e_queues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
var e2eQueueTests = []backendTest{
1717
{
18-
name: "Queues_OnlyPullsWorkflowsFromGivenQueues",
18+
name: "Queues/OnlyPullsWorkflowsFromGivenQueues",
1919
f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) {
2020
wf := func(ctx workflow.Context) (bool, error) {
2121
return true, nil

backend/test/e2e_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var e2eStatsTests = []backendTest{
1616
{
17-
name: "Stats_ActiveInstance",
17+
name: "Stats/ActiveInstance",
1818
customWorkerOptions: func(options *worker.Options) {
1919
options.ActivityQueues = []workflow.Queue{core.QueueDefault, "custom"}
2020
},

0 commit comments

Comments
 (0)