MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / TestTask_Cancel

Function TestTask_Cancel

pkg/task/task_test.go:38–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestTask_Cancel(t *testing.T) {
39 var next atomic.Uint64
40 tm := NewTaskManager(3, func(id *uint64) {
41 *id = next.Add(1)
42 })
43 id := tm.Submit(WithCancelCtx(&Task[uint64]{
44 Name: "test",
45 Func: func(task *Task[uint64]) error {
46 for {
47 if utils.IsCanceled(task.Ctx) {
48 return nil
49 } else {
50 t.Logf("task is running")
51 }
52 }
53 },
54 }))
55 task, ok := tm.Get(id)
56 if !ok {
57 t.Fatal("task not found")
58 }
59 time.Sleep(time.Microsecond * 50)
60 task.Cancel()
61 time.Sleep(time.Millisecond)
62 if task.state != CANCELED {
63 t.Errorf("task status not canceled: %s", task.state)
64 }
65}
66
67func TestTask_Retry(t *testing.T) {
68 var next atomic.Uint64

Callers

nothing calls this directly

Calls 7

IsCanceledFunction · 0.92
NewTaskManagerFunction · 0.85
WithCancelCtxFunction · 0.85
SubmitMethod · 0.80
AddMethod · 0.65
GetMethod · 0.65
CancelMethod · 0.65

Tested by

no test coverage detected