(t *testing.T)
| 234 | } |
| 235 | |
| 236 | func TestBlockQueueInitialHeight(t *testing.T) { |
| 237 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
| 238 | require.NoError(t, err) |
| 239 | const initialHeight int64 = 120 |
| 240 | |
| 241 | queue := newBlockQueue(startHeight, stopHeight, initialHeight, stopTime, 1) |
| 242 | wg := &sync.WaitGroup{} |
| 243 | |
| 244 | // asynchronously fetch blocks and add it to the queue |
| 245 | for i := 0; i <= numWorkers; i++ { |
| 246 | wg.Add(1) |
| 247 | go func() { |
| 248 | for { |
| 249 | select { |
| 250 | case height := <-queue.nextHeight(): |
| 251 | require.GreaterOrEqual(t, height, initialHeight) |
| 252 | queue.add(mockLBResp(t, peerID, height, endTime)) |
| 253 | case <-queue.done(): |
| 254 | wg.Done() |
| 255 | return |
| 256 | } |
| 257 | } |
| 258 | }() |
| 259 | } |
| 260 | |
| 261 | loop: |
| 262 | for { |
| 263 | select { |
| 264 | case <-queue.done(): |
| 265 | wg.Wait() |
| 266 | require.NoError(t, queue.error()) |
| 267 | break loop |
| 268 | |
| 269 | case resp := <-queue.verifyNext(): |
| 270 | require.GreaterOrEqual(t, resp.block.Height, initialHeight) |
| 271 | queue.success(resp.block.Height) |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | func mockLBResp(t *testing.T, peer types.NodeID, height int64, time time.Time) lightBlockResponse { |
| 277 | vals, pv := factory.RandValidatorSet(3, 10) |
nothing calls this directly
no test coverage detected
searching dependent graphs…