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

Function TestBlockQueueBasic

internal/statesync/block_queue_test.go:24–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func 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
50loop:
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
71func TestBlockQueueWithFailures(t *testing.T) {

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…