MCPcopy
hub / github.com/panjf2000/ants / TestLoopQueue

Function TestLoopQueue

worker_loop_queue_test.go:42–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestLoopQueue(t *testing.T) {
43 size := 10
44 q := newWorkerLoopQueue(size)
45
46 for i := 0; i < 5; i++ {
47 err := q.insert(&goWorker{lastUsed: time.Now().UnixNano()})
48 if err != nil {
49 break
50 }
51 }
52 require.EqualValues(t, 5, q.len(), "Len error")
53 _ = q.detach()
54 require.EqualValues(t, 4, q.len(), "Len error")
55
56 time.Sleep(time.Second)
57
58 for i := 0; i < 6; i++ {
59 err := q.insert(&goWorker{lastUsed: time.Now().UnixNano()})
60 if err != nil {
61 break
62 }
63 }
64 require.EqualValues(t, 10, q.len(), "Len error")
65
66 err := q.insert(&goWorker{lastUsed: time.Now().UnixNano()})
67 require.Error(t, err, "Enqueue, error")
68
69 q.refresh(time.Second)
70 require.EqualValuesf(t, 6, q.len(), "Len error: %d", q.len())
71}
72
73func TestRotatedQueueSearch(t *testing.T) {
74 size := 10

Callers

nothing calls this directly

Calls 5

newWorkerLoopQueueFunction · 0.85
insertMethod · 0.65
lenMethod · 0.65
detachMethod · 0.65
refreshMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…