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

Function TestSearch

worker_stack_test.go:73–115  ·  view source on GitHub ↗

It seems that something wrong with time.Now() on Windows, not sure whether it is a bug on Windows, so exclude this test from Windows platform temporarily.

(t *testing.T)

Source from the content-addressed store, hash-verified

71// It seems that something wrong with time.Now() on Windows, not sure whether it is a bug on Windows,
72// so exclude this test from Windows platform temporarily.
73func TestSearch(t *testing.T) {
74 q := newWorkerStack(0)
75
76 currTime := time.Now().UnixNano()
77
78 // 1
79 expiry1 := currTime
80 currTime++
81 _ = q.insert(&goWorker{lastUsed: currTime})
82
83 require.EqualValues(t, 0, q.binarySearch(0, q.len()-1, currTime), "index should be 0")
84 require.EqualValues(t, -1, q.binarySearch(0, q.len()-1, expiry1), "index should be -1")
85
86 // 2
87 currTime++
88 expiry2 := currTime
89 currTime++
90 _ = q.insert(&goWorker{lastUsed: currTime})
91
92 require.EqualValues(t, -1, q.binarySearch(0, q.len()-1, expiry1), "index should be -1")
93
94 require.EqualValues(t, 0, q.binarySearch(0, q.len()-1, expiry2), "index should be 0")
95
96 require.EqualValues(t, 1, q.binarySearch(0, q.len()-1, currTime), "index should be 1")
97
98 // more
99 for i := 0; i < 5; i++ {
100 currTime++
101 _ = q.insert(&goWorker{lastUsed: currTime})
102 }
103
104 currTime++
105 expiry3 := currTime
106
107 _ = q.insert(&goWorker{lastUsed: expiry3})
108
109 for i := 0; i < 10; i++ {
110 currTime++
111 _ = q.insert(&goWorker{lastUsed: currTime})
112 }
113
114 require.EqualValues(t, 7, q.binarySearch(0, q.len()-1, expiry3), "index should be 7")
115}

Callers

nothing calls this directly

Calls 4

newWorkerStackFunction · 0.85
insertMethod · 0.65
lenMethod · 0.65
binarySearchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…