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

Function TestBlockQueueStopTime

internal/statesync/block_queue_test.go:193–234  ·  view source on GitHub ↗

Test a scenario where more blocks are needed then just the stopheight because we haven't found a block with a small enough time.

(t *testing.T)

Source from the content-addressed store, hash-verified

191// Test a scenario where more blocks are needed then just the stopheight because
192// we haven't found a block with a small enough time.
193func TestBlockQueueStopTime(t *testing.T) {
194 peerID, err := types.NewNodeID("0011223344556677889900112233445566778899")
195 require.NoError(t, err)
196
197 queue := newBlockQueue(startHeight, stopHeight, 1, stopTime, 1)
198 wg := &sync.WaitGroup{}
199
200 baseTime := stopTime.Add(-50 * time.Second)
201
202 // asynchronously fetch blocks and add it to the queue
203 for i := 0; i <= numWorkers; i++ {
204 wg.Add(1)
205 go func() {
206 for {
207 select {
208 case height := <-queue.nextHeight():
209 blockTime := baseTime.Add(time.Duration(height) * time.Second)
210 queue.add(mockLBResp(t, peerID, height, blockTime))
211 case <-queue.done():
212 wg.Done()
213 return
214 }
215 }
216 }()
217 }
218
219 trackingHeight := startHeight
220 for {
221 select {
222 case resp := <-queue.verifyNext():
223 // assert that the queue serializes the blocks
224 assert.Equal(t, resp.block.Height, trackingHeight)
225 trackingHeight--
226 queue.success(resp.block.Height)
227
228 case <-queue.done():
229 wg.Wait()
230 assert.Less(t, trackingHeight, stopHeight-50)
231 return
232 }
233 }
234}
235
236func TestBlockQueueInitialHeight(t *testing.T) {
237 peerID, err := types.NewNodeID("0011223344556677889900112233445566778899")

Callers

nothing calls this directly

Calls 13

NewNodeIDFunction · 0.92
newBlockQueueFunction · 0.85
mockLBRespFunction · 0.85
nextHeightMethod · 0.80
doneMethod · 0.80
verifyNextMethod · 0.80
successMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.65
EqualMethod · 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…