MCPcopy Create free account
hub / github.com/tendermint/tendermint / TestBlockQueueBlocks

Function TestBlockQueueBlocks

internal/statesync/block_queue_test.go:121–166  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
121func 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
128loop:
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
168func TestBlockQueueAcceptsNoMoreBlocks(t *testing.T) {
169 peerID, err := types.NewNodeID("0011223344556677889900112233445566778899")

Callers

nothing calls this directly

Calls 10

NewNodeIDFunction · 0.92
newBlockQueueFunction · 0.85
mockLBRespFunction · 0.85
nextHeightMethod · 0.80
retryMethod · 0.80
EqualMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…