|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/cschleiden/go-workflows/client" |
| 9 | + "github.com/cschleiden/go-workflows/worker" |
| 10 | + "github.com/cschleiden/go-workflows/workflow" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +var e2eTimerTests = []backendTest{ |
| 15 | + { |
| 16 | + name: "Timer_ScheduleCancelRace", |
| 17 | + f: func(t *testing.T, ctx context.Context, c *client.Client, w *worker.Worker, b TestBackend) { |
| 18 | + wf := func(ctx workflow.Context) error { |
| 19 | + // 1) Start of first execution slice |
| 20 | + tctx, cancel := workflow.WithCancel(ctx) |
| 21 | + |
| 22 | + // 1) Schedule timer |
| 23 | + x := workflow.ScheduleTimer(tctx, time.Millisecond*200) |
| 24 | + |
| 25 | + // 1) Force an end to the execution slice |
| 26 | + workflow.Sleep(ctx, time.Millisecond) |
| 27 | + |
| 28 | + // 2) Start of second execution slice |
| 29 | + // 2) Cancel timer. It should not have fired at this point, |
| 30 | + // we only waited for a millisecond |
| 31 | + cancel() |
| 32 | + |
| 33 | + x.Get(ctx) |
| 34 | + |
| 35 | + // 2) Force the execution slice to be active for as long as it takes to fire the timer |
| 36 | + time.Sleep(time.Millisecond * 200) |
| 37 | + |
| 38 | + return nil |
| 39 | + } |
| 40 | + register(t, ctx, w, []interface{}{wf}, nil) |
| 41 | + |
| 42 | + _, err := runWorkflowWithResult[any](t, ctx, c, wf) |
| 43 | + require.NoError(t, err) |
| 44 | + }, |
| 45 | + }, |
| 46 | +} |
0 commit comments