(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestBlockQueueBasic(t *testing.T) { |
| 25 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
| 26 | require.NoError(t, err) |
| 27 | |
| 28 | queue := newBlockQueue(startHeight, stopHeight, 1, stopTime, 1) |
| 29 | wg := &sync.WaitGroup{} |
| 30 | |
| 31 | // asynchronously fetch blocks and add it to the queue |
| 32 | for i := 0; i <= numWorkers; i++ { |
| 33 | wg.Add(1) |
| 34 | go func() { |
| 35 | for { |
| 36 | select { |
| 37 | case height := <-queue.nextHeight(): |
| 38 | queue.add(mockLBResp(t, peerID, height, endTime)) |
| 39 | case <-queue.done(): |
| 40 | wg.Done() |
| 41 | return |
| 42 | } |
| 43 | } |
| 44 | }() |
| 45 | } |
| 46 | |
| 47 | trackingHeight := startHeight |
| 48 | wg.Add(1) |
| 49 | |
| 50 | loop: |
| 51 | for { |
| 52 | select { |
| 53 | case <-queue.done(): |
| 54 | wg.Done() |
| 55 | break loop |
| 56 | |
| 57 | case resp := <-queue.verifyNext(): |
| 58 | // assert that the queue serializes the blocks |
| 59 | require.Equal(t, resp.block.Height, trackingHeight) |
| 60 | trackingHeight-- |
| 61 | queue.success(resp.block.Height) |
| 62 | } |
| 63 | |
| 64 | } |
| 65 | |
| 66 | wg.Wait() |
| 67 | assert.Less(t, trackingHeight, stopHeight) |
| 68 | } |
| 69 | |
| 70 | // Test with spurious failures and retries |
| 71 | func TestBlockQueueWithFailures(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…