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

Function TestTask_Retry

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

Source from the content-addressed store, hash-verified

65}
66
67func TestTask_Retry(t *testing.T) {
68 var next atomic.Uint64
69 tm := NewTaskManager(3, func(id *uint64) {
70 *id = next.Add(1)
71 })
72 num := 0
73 id := tm.Submit(WithCancelCtx(&Task[uint64]{
74 Name: "test",
75 Func: func(task *Task[uint64]) error {
76 num++
77 if num&1 == 1 {
78 return errors.New("test error")
79 }
80 return nil
81 },
82 }))
83 task, ok := tm.Get(id)
84 if !ok {
85 t.Fatal("task not found")
86 }
87 time.Sleep(time.Millisecond)
88 if task.Error == nil {
89 t.Error(task.state)
90 t.Fatal("task error is nil, but expected error")
91 } else {
92 t.Logf("task error: %s", task.Error)
93 }
94 task.retry()
95 time.Sleep(time.Millisecond)
96 if task.Error != nil {
97 t.Errorf("task error: %+v, but expected nil", task.Error)
98 }
99}

Callers

nothing calls this directly

Calls 7

NewTaskManagerFunction · 0.85
WithCancelCtxFunction · 0.85
SubmitMethod · 0.80
retryMethod · 0.80
AddMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected