(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func 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 | } |
nothing calls this directly
no test coverage detected