MCPcopy
hub / github.com/kubernetes/client-go / TestHeap_BulkAdd

Function TestHeap_BulkAdd

tools/cache/heap_test.go:110–131  ·  view source on GitHub ↗

TestHeap_BulkAdd tests Heap.BulkAdd functionality and ensures that all the items given to BulkAdd are added to the queue before Pop reads them.

(t *testing.T)

Source from the content-addressed store, hash-verified

108// TestHeap_BulkAdd tests Heap.BulkAdd functionality and ensures that all the
109// items given to BulkAdd are added to the queue before Pop reads them.
110func TestHeap_BulkAdd(t *testing.T) {
111 h := NewHeap(testHeapObjectKeyFunc, compareInts)
112 const amount = 500
113 // Insert items in the heap in opposite orders in a go routine.
114 go func() {
115 l := []interface{}{}
116 for i := amount; i > 0; i-- {
117 l = append(l, mkHeapObj(string([]rune{'a', rune(i)}), i))
118 }
119 h.BulkAdd(l)
120 }()
121 prevNum := -1
122 for i := 0; i < amount; i++ {
123 obj, err := h.Pop()
124 num := obj.(testHeapObject).val.(int)
125 // All the items must be sorted.
126 if err != nil || prevNum >= num {
127 t.Errorf("got %v out of order, last was %v", obj, prevNum)
128 }
129 prevNum = num
130 }
131}
132
133// TestHeapEmptyPop tests that pop returns properly after heap is closed.
134func TestHeapEmptyPop(t *testing.T) {

Callers

nothing calls this directly

Calls 5

BulkAddMethod · 0.95
PopMethod · 0.95
NewHeapFunction · 0.85
mkHeapObjFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected