(t *testing.T)
| 71 | } |
| 72 | |
| 73 | func TestRotatedQueueSearch(t *testing.T) { |
| 74 | size := 10 |
| 75 | q := newWorkerLoopQueue(size) |
| 76 | |
| 77 | currTime := time.Now().UnixNano() |
| 78 | |
| 79 | // 1 |
| 80 | expiry1 := currTime |
| 81 | currTime++ |
| 82 | _ = q.insert(&goWorker{lastUsed: currTime}) |
| 83 | |
| 84 | require.EqualValues(t, 0, q.binarySearch(currTime), "index should be 0") |
| 85 | require.EqualValues(t, -1, q.binarySearch(expiry1), "index should be -1") |
| 86 | |
| 87 | // 2 |
| 88 | currTime++ |
| 89 | expiry2 := currTime |
| 90 | currTime++ |
| 91 | _ = q.insert(&goWorker{lastUsed: currTime}) |
| 92 | |
| 93 | require.EqualValues(t, -1, q.binarySearch(expiry1), "index should be -1") |
| 94 | |
| 95 | require.EqualValues(t, 0, q.binarySearch(expiry2), "index should be 0") |
| 96 | |
| 97 | require.EqualValues(t, 1, q.binarySearch(currTime), "index should be 1") |
| 98 | |
| 99 | // more |
| 100 | for i := 0; i < 5; i++ { |
| 101 | currTime++ |
| 102 | _ = q.insert(&goWorker{lastUsed: currTime}) |
| 103 | } |
| 104 | |
| 105 | currTime++ |
| 106 | expiry3 := currTime |
| 107 | _ = q.insert(&goWorker{lastUsed: expiry3}) |
| 108 | |
| 109 | var err error |
| 110 | for err != errQueueIsFull { |
| 111 | currTime++ |
| 112 | err = q.insert(&goWorker{lastUsed: currTime}) |
| 113 | } |
| 114 | |
| 115 | require.EqualValues(t, 7, q.binarySearch(expiry3), "index should be 7") |
| 116 | |
| 117 | // rotate |
| 118 | for i := 0; i < 6; i++ { |
| 119 | _ = q.detach() |
| 120 | } |
| 121 | |
| 122 | currTime++ |
| 123 | expiry4 := currTime |
| 124 | _ = q.insert(&goWorker{lastUsed: expiry4}) |
| 125 | |
| 126 | for i := 0; i < 4; i++ { |
| 127 | currTime++ |
| 128 | _ = q.insert(&goWorker{lastUsed: currTime}) |
| 129 | } |
| 130 | // head = 6, tail = 5, insert direction -> |
nothing calls this directly
no test coverage detected
searching dependent graphs…