(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestTask_Manager(t *testing.T) { |
| 13 | var next atomic.Uint64 |
| 14 | tm := NewTaskManager(3, func(id *uint64) { |
| 15 | *id = next.Add(1) |
| 16 | }) |
| 17 | id := tm.Submit(WithCancelCtx(&Task[uint64]{ |
| 18 | Name: "test", |
| 19 | Func: func(task *Task[uint64]) error { |
| 20 | time.Sleep(time.Millisecond * 500) |
| 21 | return nil |
| 22 | }, |
| 23 | })) |
| 24 | task, ok := tm.Get(id) |
| 25 | if !ok { |
| 26 | t.Fatal("task not found") |
| 27 | } |
| 28 | time.Sleep(time.Millisecond * 100) |
| 29 | if task.state != RUNNING { |
| 30 | t.Errorf("task status not running: %s", task.state) |
| 31 | } |
| 32 | time.Sleep(time.Second) |
| 33 | if task.state != SUCCEEDED { |
| 34 | t.Errorf("task status not finished: %s", task.state) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestTask_Cancel(t *testing.T) { |
| 39 | var next atomic.Uint64 |
nothing calls this directly
no test coverage detected