@@ -11,6 +11,7 @@ import (
11
11
"github.com/cschleiden/go-workflows/client"
12
12
"github.com/cschleiden/go-workflows/internal/core"
13
13
"github.com/cschleiden/go-workflows/internal/history"
14
+ internalwf "github.com/cschleiden/go-workflows/internal/workflow"
14
15
"github.com/cschleiden/go-workflows/worker"
15
16
"github.com/cschleiden/go-workflows/workflow"
16
17
"github.com/google/uuid"
@@ -166,7 +167,8 @@ func EndToEndBackendTest(t *testing.T, setup func() TestBackend, teardown func(b
166
167
return i * 2 , nil
167
168
}
168
169
169
- ch := make (chan struct {}, 1 )
170
+ // Workflow will be executed multiple times, but the test will wait only once. Create buffered channel
171
+ ch := make (chan struct {}, 10 )
170
172
171
173
wf := func (ctx workflow.Context ) (int , error ) {
172
174
swfs := make ([]workflow.Future [int ], 0 )
@@ -177,6 +179,7 @@ func EndToEndBackendTest(t *testing.T, setup func() TestBackend, teardown func(b
177
179
// Unblock test. Should not do this in production code, but here we know that this will be executed in the same process.
178
180
ch <- struct {}{}
179
181
182
+ // Wait for subworkflows to complete
180
183
r := 0
181
184
182
185
for _ , f := range swfs {
@@ -362,30 +365,60 @@ func EndToEndBackendTest(t *testing.T, setup func() TestBackend, teardown func(b
362
365
},
363
366
}
364
367
365
- for _ , tt := range tests {
366
- t .Run (tt .name , func (t * testing.T ) {
367
- b := setup ()
368
- ctx := context .Background ()
369
- ctx , cancel := context .WithCancel (ctx )
368
+ run := func (suffix string , workerOptions * worker.Options ) {
369
+ for _ , tt := range tests {
370
+ t .Run (tt .name + suffix , func (t * testing.T ) {
371
+ b := setup ()
372
+ ctx := context .Background ()
373
+ ctx , cancel := context .WithCancel (ctx )
370
374
371
- c := client .New (b )
372
- w := worker .New (b , & worker . DefaultWorkerOptions )
375
+ c := client .New (b )
376
+ w := worker .New (b , workerOptions )
373
377
374
- t .Cleanup (func () {
375
- cancel ()
376
- if err := w .WaitForCompletion (); err != nil {
377
- log .Println ("Worker did not stop in time" )
378
- t .FailNow ()
379
- }
378
+ t .Cleanup (func () {
379
+ cancel ()
380
+ if err := w .WaitForCompletion (); err != nil {
381
+ log .Println ("Worker did not stop in time" )
382
+ t .FailNow ()
383
+ }
380
384
381
- if teardown != nil {
382
- teardown (b )
383
- }
384
- })
385
+ if teardown != nil {
386
+ teardown (b )
387
+ }
388
+ })
385
389
386
- tt .f (t , ctx , c , w , b )
387
- })
390
+ tt .f (t , ctx , c , w , b )
391
+ })
392
+ }
388
393
}
394
+
395
+ options := worker .DefaultWorkerOptions
396
+
397
+ // Run with cache
398
+ run ("" , & options )
399
+
400
+ // Disable cache for this execution
401
+ options .WorkflowExecutorCache = & noopWorkflowExecutorCache {}
402
+ run ("_without_cache" , & options )
403
+ }
404
+
405
+ type noopWorkflowExecutorCache struct {
406
+ }
407
+
408
+ var _ internalwf.ExecutorCache = (* noopWorkflowExecutorCache )(nil )
409
+
410
+ // Get implements workflow.ExecutorCache
411
+ func (* noopWorkflowExecutorCache ) Get (ctx context.Context , instance * core.WorkflowInstance ) (internalwf.WorkflowExecutor , bool , error ) {
412
+ return nil , false , nil
413
+ }
414
+
415
+ // StartEviction implements workflow.ExecutorCache
416
+ func (* noopWorkflowExecutorCache ) StartEviction (ctx context.Context ) {
417
+ }
418
+
419
+ // Store implements workflow.ExecutorCache
420
+ func (* noopWorkflowExecutorCache ) Store (ctx context.Context , instance * core.WorkflowInstance , workflow internalwf.WorkflowExecutor ) error {
421
+ return nil
389
422
}
390
423
391
424
func register (t * testing.T , ctx context.Context , w worker.Worker , workflows []interface {}, activities []interface {}) {
0 commit comments