-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_test.go
More file actions
643 lines (606 loc) · 19.2 KB
/
Copy pathtask_test.go
File metadata and controls
643 lines (606 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
package durable_test
import (
"context"
"errors"
"log/slog"
"strings"
"sync/atomic"
"testing"
"time"
durable "github.com/agenticenv/durable-go"
)
func identityTask() durable.TaskFunc[string, string] {
return durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
return durable.RunStep(ctx, s, "echo", func(ctx context.Context) (string, error) {
return in, nil
}).Get(ctx)
})
}
func TestRegisterTask_Success(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask(), durable.WithName("Echo"), durable.WithTag("k", "v")); err != nil {
t.Fatal(err)
}
}
func TestRegisterTask_Duplicate(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask()); err != nil {
t.Fatal(err)
}
err := durable.RegisterTask(e, "echo", identityTask())
if !errors.Is(err, durable.ErrTaskAlreadyRegistered) {
t.Fatalf("got %v", err)
}
}
func TestRegisterTask_InvalidTaskID(t *testing.T) {
e := newTestEngine(t)
for _, id := range []string{"", "a/b", `a\b`, "a..b", "a:b", "..", "."} {
err := durable.RegisterTask(e, id, identityTask())
if err == nil {
t.Fatalf("id %q: expected error", id)
}
}
}
func TestRunTask_NotRegistered(t *testing.T) {
e := newTestEngine(t)
run := durable.RunTask[string, string](context.Background(), e, "missing", "", "x")
if run.RunID() != "" {
t.Fatalf("RunID should be empty, got %q", run.RunID())
}
_, err := run.Get(context.Background())
if !errors.Is(err, durable.ErrTaskNotRegistered) {
t.Fatalf("got %v", err)
}
}
func TestRunTask_InvalidTaskID(t *testing.T) {
e := newTestEngine(t)
run := durable.RunTask[string, string](context.Background(), e, "bad/id", "", "x")
_, err := run.Get(context.Background())
if err == nil || !strings.Contains(err.Error(), "invalid task ID") {
t.Fatalf("got %v", err)
}
}
func TestRunTask_NewRun(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask(), durable.WithName("Echo")); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "echo", "", "hello")
if run.RunID() == "" {
t.Fatal("RunID should be available immediately")
}
out, err := run.Get(context.Background())
if err != nil {
t.Fatal(err)
}
if out != "hello" {
t.Fatalf("got %q", out)
}
if run.Status() != durable.StatusCompleted {
t.Fatalf("status %s", run.Status())
}
info, ok, err := e.GetTask(context.Background(), "echo", run.RunID())
if err != nil || !ok {
t.Fatalf("GetTask: ok=%v err=%v", ok, err)
}
if info.Name != "Echo" || info.Status != durable.StatusCompleted {
t.Fatalf("info %+v", info)
}
}
func TestRunTask_RunIDAvailableBeforeGet(t *testing.T) {
e := newTestEngine(t)
started := make(chan struct{})
if err := durable.RegisterTask(e, "slow", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
close(started)
<-ctx.Done()
return "", ctx.Err()
}), durable.WithTaskTimeout(50*time.Millisecond)); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "slow", "", "x")
if run.RunID() == "" {
t.Fatal("RunID empty before Get")
}
select {
case <-started:
case <-time.After(2 * time.Second):
t.Fatal("task did not start")
}
_, _ = run.Get(context.Background())
}
func TestRunTask_GetBlocksThenReturns(t *testing.T) {
e := newTestEngine(t)
release := make(chan struct{})
if err := durable.RegisterTask(e, "block", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
<-release
return in, nil
})); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "block", "", "done")
done := make(chan struct{})
var out string
var err error
go func() {
out, err = run.Get(context.Background())
close(done)
}()
select {
case <-done:
t.Fatal("Get returned before release")
case <-time.After(50 * time.Millisecond):
}
close(release)
select {
case <-done:
case <-time.After(2 * time.Second):
t.Fatal("Get did not return")
}
if err != nil || out != "done" {
t.Fatalf("out=%q err=%v", out, err)
}
}
func TestRunTask_StatusPolling(t *testing.T) {
e := newTestEngine(t)
release := make(chan struct{})
if err := durable.RegisterTask(e, "poll", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
<-release
return "ok", nil
})); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "poll", "", "")
deadline := time.Now().Add(2 * time.Second)
for run.Status() != durable.StatusRunning && time.Now().Before(deadline) {
time.Sleep(5 * time.Millisecond)
}
if run.Status() != durable.StatusRunning {
t.Fatalf("status %s", run.Status())
}
close(release)
if _, err := run.Get(context.Background()); err != nil {
t.Fatal(err)
}
if run.Status() != durable.StatusCompleted {
t.Fatalf("status %s", run.Status())
}
}
func TestRunTask_IdempotentRunID(t *testing.T) {
e := newTestEngine(t)
var n atomic.Int32
if err := durable.RegisterTask(e, "once", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
n.Add(1)
return durable.RunStep(ctx, s, "s", func(ctx context.Context) (string, error) {
return in, nil
}).Get(ctx)
})); err != nil {
t.Fatal(err)
}
const runID = "req-42"
r1 := durable.RunTask[string, string](context.Background(), e, "once", runID, "a")
out1, err := r1.Get(context.Background())
if err != nil {
t.Fatal(err)
}
r2 := durable.RunTask[string, string](context.Background(), e, "once", runID, "b")
out2, err := r2.Get(context.Background())
if err != nil {
t.Fatal(err)
}
if out1 != "a" || out2 != "a" {
t.Fatalf("out1=%q out2=%q", out1, out2)
}
if n.Load() != 1 {
t.Fatalf("closure invoked %d times", n.Load())
}
}
func TestRunTask_CompletedReturnsStoredOutput(t *testing.T) {
e := newTestEngine(t)
var n atomic.Int32
if err := durable.RegisterTask(e, "store", durable.Func(func(ctx context.Context, s *durable.StepRunner, in int) (int, error) {
n.Add(1)
return in + 1, nil
})); err != nil {
t.Fatal(err)
}
r1 := durable.RunTask[int, int](context.Background(), e, "store", "r1", 10)
out, err := r1.Get(context.Background())
if err != nil || out != 11 {
t.Fatalf("out=%d err=%v", out, err)
}
r2 := durable.RunTask[int, int](context.Background(), e, "store", "r1", 99)
out, err = r2.Get(context.Background())
if err != nil || out != 11 {
t.Fatalf("stored out=%d err=%v", out, err)
}
if n.Load() != 1 {
t.Fatalf("invocations %d", n.Load())
}
}
func TestRunTask_ResumeReplaysSteps(t *testing.T) {
dir := t.TempDir()
ctx := context.Background()
var steps atomic.Int32
task := durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
a, err := durable.RunStep(ctx, s, "one", func(ctx context.Context) (string, error) {
steps.Add(1)
return "A", nil
}).Get(ctx)
if err != nil {
return "", err
}
b, err := durable.RunStep(ctx, s, "two", func(ctx context.Context) (string, error) {
steps.Add(1)
return a + "B", nil
}).Get(ctx)
if err != nil {
return "", err
}
return b, nil
})
e1, err := durable.NewEngine(ctx, dir)
if err != nil {
t.Fatal(err)
}
if err := durable.RegisterTask(e1, "resume", task); err != nil {
t.Fatal(err)
}
r1 := durable.RunTask[string, string](ctx, e1, "resume", "run-1", "")
out, err := r1.Get(ctx)
if err != nil || out != "AB" {
t.Fatalf("out=%q err=%v", out, err)
}
if err := e1.Close(); err != nil {
t.Fatal(err)
}
e2, err := durable.NewEngine(ctx, dir)
if err != nil {
t.Fatal(err)
}
defer func() { _ = e2.Close() }()
if err := durable.RegisterTask(e2, "resume", task); err != nil {
t.Fatal(err)
}
r2 := durable.RunTask[string, string](ctx, e2, "resume", "run-1", "")
out, err = r2.Get(ctx)
if err != nil || out != "AB" {
t.Fatalf("resume out=%q err=%v", out, err)
}
if steps.Load() != 2 {
t.Fatalf("steps executed %d, want 2 (no re-exec on resume of completed run)", steps.Load())
}
}
func TestRunTask_EmptyRunIDResumesOldestActive(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "single", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
token := ""
_, err := durable.RunStep(ctx, s, "wait", func(ctx context.Context) (string, error) {
token = s.StepToken()
return "", durable.ErrStepPending
}).Get(ctx)
return token, err
})); err != nil {
t.Fatal(err)
}
r1 := durable.RunTask[string, string](context.Background(), e, "single", "", "")
deadline := time.Now().Add(2 * time.Second)
for r1.Status() != durable.StatusWaiting && time.Now().Before(deadline) {
time.Sleep(5 * time.Millisecond)
}
if r1.Status() != durable.StatusWaiting {
t.Fatalf("status %s", r1.Status())
}
r2 := durable.RunTask[string, string](context.Background(), e, "single", "", "")
if r2.RunID() != r1.RunID() {
t.Fatalf("empty runID should resume singleton: %q vs %q", r2.RunID(), r1.RunID())
}
info, ok, err := e.GetTask(context.Background(), "single", r1.RunID())
if err != nil || !ok {
t.Fatal(err)
}
_ = info
}
func TestRunTask_InvalidRunID(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask()); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "echo", "a/b", "x")
_, err := run.Get(context.Background())
if !errors.Is(err, durable.ErrInvalidRunID) {
t.Fatalf("got %v", err)
}
}
func TestRunTask_PurgeThenRetry(t *testing.T) {
e := newTestEngine(t)
var n atomic.Int32
if err := durable.RegisterTask(e, "p", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
n.Add(1)
return in, nil
})); err != nil {
t.Fatal(err)
}
r1 := durable.RunTask[string, string](context.Background(), e, "p", "rid", "first")
if _, err := r1.Get(context.Background()); err != nil {
t.Fatal(err)
}
if err := e.DeleteTaskRun(context.Background(), "p", "rid"); err != nil {
t.Fatal(err)
}
r2 := durable.RunTask[string, string](context.Background(), e, "p", "rid", "second")
out, err := r2.Get(context.Background())
if err != nil {
t.Fatal(err)
}
if out != "second" {
t.Fatalf("got %q", out)
}
if n.Load() != 2 {
t.Fatalf("invocations %d", n.Load())
}
}
func TestRunTask_StaleDetectionViaListTasks(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "stale", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
_, err := durable.RunStep(ctx, s, "wait", func(ctx context.Context) (string, error) {
return "", durable.ErrStepPending
}).Get(ctx)
return "", err
})); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "stale", "s1", "")
deadline := time.Now().Add(2 * time.Second)
for run.Status() != durable.StatusWaiting && time.Now().Before(deadline) {
time.Sleep(5 * time.Millisecond)
}
pending, err := e.ListTasks(context.Background(), durable.StatusRunning, durable.StatusWaiting)
if err != nil {
t.Fatal(err)
}
if len(pending) != 1 || pending[0].RunID != "s1" {
t.Fatalf("pending %+v", pending)
}
}
func TestRunTask_GetCancelled(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "hang", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
<-ctx.Done()
return "", ctx.Err()
}), durable.WithTaskTimeout(time.Hour)); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "hang", "", "")
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
defer cancel()
_, err := run.Get(ctx)
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("got %v", err)
}
}
func TestRunTask_FailedReturnsError(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "fail", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
return "", errors.New("boom")
})); err != nil {
t.Fatal(err)
}
run := durable.RunTask[string, string](context.Background(), e, "fail", "f1", "")
_, err := run.Get(context.Background())
if err == nil || err.Error() != "boom" {
t.Fatalf("got %v", err)
}
run2 := durable.RunTask[string, string](context.Background(), e, "fail", "f1", "")
_, err = run2.Get(context.Background())
if err == nil || err.Error() != "boom" {
t.Fatalf("stored fail: %v", err)
}
}
func TestOptionResolution_RunOverridesEngine(t *testing.T) {
e := newTestEngine(t, durable.WithMaxRetries(3), durable.WithLogger(slog.Default()))
var n atomic.Int32
if err := durable.RegisterTask(e, "opt", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
n.Add(1)
return "", errors.New("non-step")
})); err != nil {
t.Fatal(err)
}
_, err := durable.RunTask[string, string](context.Background(), e, "opt", "r", "", durable.WithRunMaxRetries(0)).Get(context.Background())
if err == nil {
t.Fatal("expected error")
}
if n.Load() != 1 {
t.Fatalf("explicit 0 should disable engine retries, got %d", n.Load())
}
}
func TestTaskMaxRetries_RetriesPanic(t *testing.T) {
e := newTestEngine(t)
var n atomic.Int32
if err := durable.RegisterTask(e, "tr", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
if n.Add(1) == 1 {
panic("once")
}
return "ok", nil
}), durable.WithTaskMaxRetries(1)); err != nil {
t.Fatal(err)
}
out, err := durable.RunTask[string, string](context.Background(), e, "tr", "", "").Get(context.Background())
if err != nil || out != "ok" {
t.Fatalf("out=%q err=%v", out, err)
}
if n.Load() != 2 {
t.Fatalf("attempts %d", n.Load())
}
}
func TestTaskRetries_DoNotRetryStepError(t *testing.T) {
e := newTestEngine(t)
var n atomic.Int32
if err := durable.RegisterTask(e, "sr", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
n.Add(1)
return durable.RunStep(ctx, s, "f", func(ctx context.Context) (string, error) {
return "", errors.New("step-fail")
}).Get(ctx)
}), durable.WithTaskMaxRetries(3)); err != nil {
t.Fatal(err)
}
_, err := durable.RunTask[string, string](context.Background(), e, "sr", "", "").Get(context.Background())
if err == nil {
t.Fatal("expected error")
}
if n.Load() != 1 {
t.Fatalf("task retried a step error: %d", n.Load())
}
}
func TestWithRunTimeout(t *testing.T) {
e := newTestEngine(t, durable.WithTimeout(time.Hour))
if err := durable.RegisterTask(e, "to", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
<-ctx.Done()
return "", ctx.Err()
})); err != nil {
t.Fatal(err)
}
_, err := durable.RunTask[string, string](context.Background(), e, "to", "", "", durable.WithRunTimeout(20*time.Millisecond)).Get(context.Background())
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("got %v", err)
}
}
func TestListTasks_FilterAndAll(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "ok", identityTask()); err != nil {
t.Fatal(err)
}
if err := durable.RegisterTask(e, "fail", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
return "", errors.New("no")
})); err != nil {
t.Fatal(err)
}
if _, err := durable.RunTask[string, string](context.Background(), e, "ok", "a", "x").Get(context.Background()); err != nil {
t.Fatal(err)
}
_, _ = durable.RunTask[string, string](context.Background(), e, "fail", "b", "x").Get(context.Background())
all, err := e.ListTasks(context.Background())
if err != nil {
t.Fatal(err)
}
if len(all) != 2 {
t.Fatalf("all=%d", len(all))
}
completed, err := e.ListTasks(context.Background(), durable.StatusCompleted)
if err != nil {
t.Fatal(err)
}
if len(completed) != 1 || completed[0].RunID != "a" {
t.Fatalf("%+v", completed)
}
failed, err := e.ListTasks(context.Background(), durable.StatusFailed)
if err != nil {
t.Fatal(err)
}
if len(failed) != 1 || failed[0].RunID != "b" {
t.Fatalf("%+v", failed)
}
}
func TestGetTask_NotFound(t *testing.T) {
e := newTestEngine(t)
_, ok, err := e.GetTask(context.Background(), "missing", "r")
if err != nil || ok {
t.Fatalf("ok=%v err=%v", ok, err)
}
}
func TestLoadSteps_OrderedBySeq(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "seq", durable.Func(func(ctx context.Context, s *durable.StepRunner, in string) (string, error) {
if _, err := durable.RunStep(ctx, s, "a", func(ctx context.Context) (string, error) { return "1", nil }).Get(ctx); err != nil {
return "", err
}
if _, err := durable.RunStep(ctx, s, "b", func(ctx context.Context) (string, error) { return "2", nil }).Get(ctx); err != nil {
return "", err
}
return "ok", nil
})); err != nil {
t.Fatal(err)
}
if _, err := durable.RunTask[string, string](context.Background(), e, "seq", "r", "").Get(context.Background()); err != nil {
t.Fatal(err)
}
steps, err := e.LoadSteps(context.Background(), "seq", "r")
if err != nil {
t.Fatal(err)
}
if len(steps) != 2 || steps[0].StepID != "a" || steps[1].StepID != "b" {
t.Fatalf("%+v", steps)
}
if steps[0].Seq != 1 || steps[1].Seq != 2 {
t.Fatalf("seq %+v", steps)
}
}
func TestDeleteTaskRun(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask()); err != nil {
t.Fatal(err)
}
if _, err := durable.RunTask[string, string](context.Background(), e, "echo", "r1", "x").Get(context.Background()); err != nil {
t.Fatal(err)
}
if err := e.DeleteTaskRun(context.Background(), "echo", "r1"); err != nil {
t.Fatal(err)
}
_, ok, err := e.GetTask(context.Background(), "echo", "r1")
if err != nil || ok {
t.Fatalf("ok=%v err=%v", ok, err)
}
if err := e.DeleteTaskRun(context.Background(), "echo", "r1"); err != nil {
t.Fatalf("no-op delete: %v", err)
}
}
func TestDeleteTask(t *testing.T) {
e := newTestEngine(t)
if err := durable.RegisterTask(e, "echo", identityTask()); err != nil {
t.Fatal(err)
}
if _, err := durable.RunTask[string, string](context.Background(), e, "echo", "r1", "x").Get(context.Background()); err != nil {
t.Fatal(err)
}
if _, err := durable.RunTask[string, string](context.Background(), e, "echo", "r2", "y").Get(context.Background()); err != nil {
t.Fatal(err)
}
if err := e.DeleteTask(context.Background(), "echo"); err != nil {
t.Fatal(err)
}
all, err := e.ListTasks(context.Background())
if err != nil {
t.Fatal(err)
}
if len(all) != 0 {
t.Fatalf("left %+v", all)
}
}
func TestDeleteTask_ActiveReturnsErrRunActive(t *testing.T) {
e := newTestEngine(t)
registerApproval(t, e, nil)
run := durable.RunTask[string, approval](context.Background(), e, "approve", "r1", "")
waitUntil(t, 2*time.Second, func() bool { return run.Status() == durable.StatusWaiting })
err := e.DeleteTask(context.Background(), "approve")
if !errors.Is(err, durable.ErrRunActive) {
t.Fatalf("got %v", err)
}
}
func TestListTasks_Empty(t *testing.T) {
e := newTestEngine(t)
all, err := e.ListTasks(context.Background())
if err != nil {
t.Fatal(err)
}
if len(all) != 0 {
t.Fatalf("%+v", all)
}
}
func TestGetTask_InvalidIDs(t *testing.T) {
e := newTestEngine(t)
if _, _, err := e.GetTask(context.Background(), "a/b", "r"); err == nil {
t.Fatal("expected invalid taskID")
}
if _, _, err := e.GetTask(context.Background(), "t", "a/b"); !errors.Is(err, durable.ErrInvalidRunID) {
t.Fatalf("got %v", err)
}
}