Skip to content

Commit 99cb895

Browse files
committed
Remove Worker interface, return type instead
1 parent db8a980 commit 99cb895

File tree

13 files changed

+47
-68
lines changed

13 files changed

+47
-68
lines changed

backend/test/e2e.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ type backendTest struct {
2323
name string
2424
options []backend.BackendOption
2525
withoutCache bool // If set, test will only be run when the cache is disabled
26-
f func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend)
26+
f func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend)
2727
}
2828

2929
func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOption) TestBackend, teardown func(b TestBackend)) {
3030
tests := []backendTest{
3131
{
3232
name: "SimpleWorkflow",
33-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
33+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
3434
wf := func(ctx workflow.Context, msg string) (string, error) {
3535
return msg + " world", nil
3636
}
@@ -44,7 +44,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
4444
},
4545
{
4646
name: "SimpleWorkflow_ExpectedHistory",
47-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
47+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
4848
wf := func(ctx workflow.Context, msg string) (string, error) {
4949
return msg + " world", nil
5050
}
@@ -66,7 +66,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
6666
},
6767
{
6868
name: "UnregisteredWorkflow_Errors",
69-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
69+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
7070
wf := func(ctx workflow.Context, msg string) (string, error) {
7171
return msg + " world", nil
7272
}
@@ -80,7 +80,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
8080
},
8181
{
8282
name: "WorkflowArgumentMismatch",
83-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
83+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
8484
wf := func(ctx workflow.Context, p1 int) (int, error) {
8585
return 42, nil
8686
}
@@ -96,7 +96,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
9696
},
9797
{
9898
name: "UnregisteredActivity_Errors",
99-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
99+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
100100
a := func(context.Context) error { return nil }
101101
wf := func(ctx workflow.Context) (int, error) {
102102
return workflow.ExecuteActivity[int](ctx, workflow.ActivityOptions{
@@ -115,7 +115,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
115115
},
116116
{
117117
name: "ActivityArgumentMismatch",
118-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
118+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
119119
a := func(context.Context, int, int) error { return nil }
120120
wf := func(ctx workflow.Context) (int, error) {
121121
return workflow.ExecuteActivity[int](ctx, workflow.ActivityOptions{
@@ -134,7 +134,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
134134
},
135135
{
136136
name: "SideEffect_Simple",
137-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
137+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
138138
i := 2
139139
wf := func(ctx workflow.Context) (int, error) {
140140
r1, _ := workflow.SideEffect(ctx, func(ctx workflow.Context) int {
@@ -163,7 +163,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
163163
},
164164
{
165165
name: "Signal_after_completion",
166-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
166+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
167167
wf := func(ctx workflow.Context) error {
168168
return nil
169169
}
@@ -180,7 +180,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
180180
},
181181
{
182182
name: "SubWorkflow_Simple",
183-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
183+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
184184
swf := func(ctx workflow.Context, i int) (int, error) {
185185
return i * 2, nil
186186
}
@@ -203,7 +203,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
203203
},
204204
{
205205
name: "SubWorkflow_PropagateCancellation",
206-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
206+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
207207
canceled := int32(0)
208208

209209
swf := func(ctx workflow.Context, i int) (int, error) {
@@ -267,7 +267,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
267267
},
268268
{
269269
name: "SubWorkflow_CancelBeforeStarting",
270-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
270+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
271271
swInstanceID := "subworkflow"
272272

273273
swfrun := 0
@@ -313,7 +313,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
313313
},
314314
{
315315
name: "SubWorkflow_Signal",
316-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
316+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
317317
swf := func(ctx workflow.Context, i int) (int, error) {
318318
workflow.NewSignalChannel[string](ctx, "signal").Receive(ctx)
319319

@@ -347,7 +347,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
347347
},
348348
{
349349
name: "SubWorkflow_Signal_BeforeStarting",
350-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
350+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
351351
wf := func(ctx workflow.Context) (int, error) {
352352
id, _ := workflow.SideEffect(ctx, func(ctx workflow.Context) string {
353353
id := uuid.New().String()
@@ -371,7 +371,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
371371
},
372372
{
373373
name: "Timer_CancelWorkflowInstance",
374-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
374+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
375375
a := func(ctx context.Context) error {
376376
return nil
377377
}
@@ -398,7 +398,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
398398
},
399399
{
400400
name: "Timer_CancelBeforeStarting",
401-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
401+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
402402
a := func(ctx context.Context) error {
403403
return nil
404404
}
@@ -441,7 +441,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
441441
},
442442
{
443443
name: "Timer_CancelTwice",
444-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
444+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
445445
a := func(ctx context.Context) error {
446446
return nil
447447
}
@@ -484,7 +484,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
484484
},
485485
{
486486
name: "Timer_CancelBeforeFiringRemovesFutureEvent",
487-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
487+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
488488
a := func(ctx context.Context) error {
489489
return nil
490490
}
@@ -523,7 +523,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
523523
{
524524
name: "NonDeterminism",
525525
withoutCache: true,
526-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
526+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
527527
i := 0
528528
wf := func(ctx workflow.Context) (int, error) {
529529
var r int
@@ -553,7 +553,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
553553
},
554554
{
555555
name: "RemoveWorkflowInstance",
556-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
556+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
557557
wf := func(ctx workflow.Context, msg string) (string, error) {
558558
return msg + " world", nil
559559
}
@@ -576,7 +576,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
576576
{
577577
name: "ContextPropagation",
578578
options: []backend.BackendOption{backend.WithContextPropagator(&testContextPropagator{})},
579-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
579+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
580580
a := func(ctx context.Context) (int, error) {
581581
d := myValues(ctx)
582582
return d.Count, nil
@@ -610,7 +610,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
610610
},
611611
{
612612
name: "ContinueAsNew",
613-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
613+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
614614
wf := func(ctx workflow.Context, run int) (int, error) {
615615
run = run + 1
616616
if run < 3 {
@@ -634,7 +634,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
634634
},
635635
{
636636
name: "ContinueAsNew_Subworkflow",
637-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
637+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
638638
swf := func(ctx workflow.Context, run int) (int, error) {
639639
l := workflow.Logger(ctx)
640640

@@ -727,7 +727,7 @@ func (*noopWorkflowExecutorCache) Store(ctx context.Context, instance *core.Work
727727
return nil
728728
}
729729

730-
func register(t *testing.T, ctx context.Context, w worker.Worker, workflows []interface{}, activities []interface{}) {
730+
func register(t *testing.T, ctx context.Context, w *worker.Worker, workflows []interface{}, activities []interface{}) {
731731
for _, wf := range workflows {
732732
require.NoError(t, w.RegisterWorkflow(wf))
733733
}

backend/test/e2e_activity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (e *CustomError) Error() string {
2222
var e2eActivityTests = []backendTest{
2323
{
2424
name: "Activity_Panic",
25-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
25+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
2626
a := func(context.Context) error {
2727
panic("activity panic")
2828
}
@@ -47,7 +47,7 @@ var e2eActivityTests = []backendTest{
4747
},
4848
{
4949
name: "Activity_CustomError",
50-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
50+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
5151
a := func(context.Context) error {
5252
return &CustomError{msg: "custom error"}
5353
}

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
var e2eStatsTests = []backendTest{
1515
{
1616
name: "Stats_ActiveInstance",
17-
f: func(t *testing.T, ctx context.Context, c client.Client, w worker.Worker, b TestBackend) {
17+
f: func(t *testing.T, ctx context.Context, c client.Client, w *worker.Worker, b TestBackend) {
1818
as := make(chan bool, 1)
1919
af := make(chan bool, 1)
2020

contextpropagation/contextpropagator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/cschleiden/go-workflows/internal/sync"
88
)
99

10+
// TODO!
1011
type ContextPropagator interface {
1112
Inject(context.Context, *metadata.WorkflowMetadata) error
1213
Extract(context.Context, *metadata.WorkflowMetadata) (context.Context, error)

samples/context-propagation/context_propagation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func runWorkflow(ctx context.Context, c client.Client) {
5555
log.Println("Workflow finished. Result:", result)
5656
}
5757

58-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
58+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
5959
w := worker.New(mb, nil)
6060

6161
w.RegisterWorkflow(Workflow1)

samples/continue-as-new/continue-as-new.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func runWorkflow(ctx context.Context, c client.Client) {
7171
log.Println("Workflow finished. Result:", result)
7272
}
7373

74-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
74+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
7575
w := worker.New(mb, nil)
7676

7777
w.RegisterWorkflow(Workflow1)

samples/converter/converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func runWorkflow(ctx context.Context, c client.Client) {
8383
log.Println("Workflow finished. Result:", result)
8484
}
8585

86-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
86+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
8787
w := worker.New(mb, nil)
8888

8989
w.RegisterWorkflow(Workflow1)

samples/simple/simple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func runWorkflow(ctx context.Context, c client.Client) {
5353
log.Println("Workflow finished. Result:", result)
5454
}
5555

56-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
56+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
5757
w := worker.New(mb, nil)
5858

5959
w.RegisterWorkflow(Workflow1)

samples/subworkflow/subworkflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func startWorkflow(ctx context.Context, c client.Client) {
5353
log.Println("Workflow finished. Result:", result)
5454
}
5555

56-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
56+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
5757
w := worker.New(mb, nil)
5858

5959
w.RegisterWorkflow(ParentWorkflow)

samples/timer/timer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func startWorkflow(ctx context.Context, c client.Client) {
4848
log.Println("Workflow finished. Result:", result)
4949
}
5050

51-
func RunWorker(ctx context.Context, mb backend.Backend) worker.Worker {
51+
func RunWorker(ctx context.Context, mb backend.Backend) *worker.Worker {
5252
w := worker.New(mb, nil)
5353

5454
w.RegisterWorkflow(Workflow1)

0 commit comments

Comments
 (0)