Test a scenario where more blocks are needed then just the stopheight because we haven't found a block with a small enough time.
(t *testing.T)
| 191 | // Test a scenario where more blocks are needed then just the stopheight because |
| 192 | // we haven't found a block with a small enough time. |
| 193 | func TestBlockQueueStopTime(t *testing.T) { |
| 194 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
| 195 | require.NoError(t, err) |
| 196 | |
| 197 | queue := newBlockQueue(startHeight, stopHeight, 1, stopTime, 1) |
| 198 | wg := &sync.WaitGroup{} |
| 199 | |
| 200 | baseTime := stopTime.Add(-50 * time.Second) |
| 201 | |
| 202 | // asynchronously fetch blocks and add it to the queue |
| 203 | for i := 0; i <= numWorkers; i++ { |
| 204 | wg.Add(1) |
| 205 | go func() { |
| 206 | for { |
| 207 | select { |
| 208 | case height := <-queue.nextHeight(): |
| 209 | blockTime := baseTime.Add(time.Duration(height) * time.Second) |
| 210 | queue.add(mockLBResp(t, peerID, height, blockTime)) |
| 211 | case <-queue.done(): |
| 212 | wg.Done() |
| 213 | return |
| 214 | } |
| 215 | } |
| 216 | }() |
| 217 | } |
| 218 | |
| 219 | trackingHeight := startHeight |
| 220 | for { |
| 221 | select { |
| 222 | case resp := <-queue.verifyNext(): |
| 223 | // assert that the queue serializes the blocks |
| 224 | assert.Equal(t, resp.block.Height, trackingHeight) |
| 225 | trackingHeight-- |
| 226 | queue.success(resp.block.Height) |
| 227 | |
| 228 | case <-queue.done(): |
| 229 | wg.Wait() |
| 230 | assert.Less(t, trackingHeight, stopHeight-50) |
| 231 | return |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | func TestBlockQueueInitialHeight(t *testing.T) { |
| 237 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
nothing calls this directly
no test coverage detected
searching dependent graphs…