(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func 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 | |
| 67 | func TestTask_Retry(t *testing.T) { |
| 68 | var next atomic.Uint64 |
nothing calls this directly
no test coverage detected