Skip to content

Commit 63443d1

Browse files
committed
Add failing test case
1 parent e756c08 commit 63443d1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

backend/test/e2e.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ func EndToEndBackendTest(t *testing.T, setup func(options ...backend.BackendOpti
779779
}
780780

781781
tests = append(tests, e2eActivityTests...)
782+
tests = append(tests, e2eTimerTests...)
782783
tests = append(tests, e2eStatsTests...)
783784

784785
run := func(suffix string, workerOptions worker.Options) {

backend/test/e2e_timer.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)