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

Function TestTask_Manager

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

Source from the content-addressed store, hash-verified

10)
11
12func 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
38func TestTask_Cancel(t *testing.T) {
39 var next atomic.Uint64

Callers

nothing calls this directly

Calls 5

NewTaskManagerFunction · 0.85
WithCancelCtxFunction · 0.85
SubmitMethod · 0.80
AddMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected