Test that when all the blocks are retrieved that the queue still holds on to it's workers and in the event of failure can still fetch the failed block
(t *testing.T)
| 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 |
| 121 | func TestBlockQueueBlocks(t *testing.T) { |
| 122 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
| 123 | require.NoError(t, err) |
| 124 | queue := newBlockQueue(startHeight, stopHeight, 1, stopTime, 2) |
| 125 | expectedHeight := startHeight |
| 126 | retryHeight := stopHeight + 2 |
| 127 | |
| 128 | loop: |
| 129 | for { |
| 130 | select { |
| 131 | case height := <-queue.nextHeight(): |
| 132 | require.Equal(t, height, expectedHeight) |
| 133 | require.GreaterOrEqual(t, height, stopHeight) |
| 134 | expectedHeight-- |
| 135 | queue.add(mockLBResp(t, peerID, height, endTime)) |
| 136 | case <-time.After(1 * time.Second): |
| 137 | if expectedHeight >= stopHeight { |
| 138 | t.Fatalf("expected next height %d", expectedHeight) |
| 139 | } |
| 140 | break loop |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // close any waiter channels that the previous worker left hanging |
| 145 | for _, ch := range queue.waiters { |
| 146 | close(ch) |
| 147 | } |
| 148 | queue.waiters = make([]chan int64, 0) |
| 149 | |
| 150 | wg := &sync.WaitGroup{} |
| 151 | wg.Add(1) |
| 152 | // so far so good. The worker is waiting. Now we fail a previous |
| 153 | // block and check that the worker fetches them |
| 154 | go func(t *testing.T) { |
| 155 | defer wg.Done() |
| 156 | select { |
| 157 | case height := <-queue.nextHeight(): |
| 158 | require.Equal(t, retryHeight, height) |
| 159 | case <-time.After(1 * time.Second): |
| 160 | require.Fail(t, "queue didn't ask worker to fetch failed height") |
| 161 | } |
| 162 | }(t) |
| 163 | queue.retry(retryHeight) |
| 164 | wg.Wait() |
| 165 | |
| 166 | } |
| 167 | |
| 168 | func TestBlockQueueAcceptsNoMoreBlocks(t *testing.T) { |
| 169 | peerID, err := types.NewNodeID("0011223344556677889900112233445566778899") |
nothing calls this directly
no test coverage detected
searching dependent graphs…