Test with spurious failures and retries
(t *testing.T)
| 69 | |
| 70 | // Test with spurious failures and retries |
| 71 | func TestBlockQueueWithFailures(t *testing.T) { |
| 72 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
| 73 | require.NoError(t, err) |
| 74 | |
| 75 | queue := newBlockQueue(startHeight, stopHeight, 1, stopTime, 200) |
| 76 | wg := &sync.WaitGroup{} |
| 77 | |
| 78 | failureRate := 4 |
| 79 | for i := 0; i <= numWorkers; i++ { |
| 80 | wg.Add(1) |
| 81 | go func() { |
| 82 | for { |
| 83 | select { |
| 84 | case height := <-queue.nextHeight(): |
| 85 | if rand.Intn(failureRate) == 0 { |
| 86 | queue.retry(height) |
| 87 | } else { |
| 88 | queue.add(mockLBResp(t, peerID, height, endTime)) |
| 89 | } |
| 90 | case <-queue.done(): |
| 91 | wg.Done() |
| 92 | return |
| 93 | } |
| 94 | } |
| 95 | }() |
| 96 | } |
| 97 | |
| 98 | trackingHeight := startHeight |
| 99 | for { |
| 100 | select { |
| 101 | case resp := <-queue.verifyNext(): |
| 102 | // assert that the queue serializes the blocks |
| 103 | assert.Equal(t, resp.block.Height, trackingHeight) |
| 104 | if rand.Intn(failureRate) == 0 { |
| 105 | queue.retry(resp.block.Height) |
| 106 | } else { |
| 107 | trackingHeight-- |
| 108 | queue.success(resp.block.Height) |
| 109 | } |
| 110 | |
| 111 | case <-queue.done(): |
| 112 | wg.Wait() |
| 113 | assert.Less(t, trackingHeight, stopHeight) |
| 114 | return |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Test that when all the blocks are retrieved that the queue still holds on to |
| 120 | // it's workers and in the event of failure can still fetch the failed block |
nothing calls this directly
no test coverage detected
searching dependent graphs…