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

Function TestBlockQueueWithFailures

internal/statesync/block_queue_test.go:71–117  ·  view source on GitHub ↗

Test with spurious failures and retries

(t *testing.T)

Source from the content-addressed store, hash-verified

69
70// Test with spurious failures and retries
71func 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

Callers

nothing calls this directly

Calls 14

NewNodeIDFunction · 0.92
newBlockQueueFunction · 0.85
mockLBRespFunction · 0.85
nextHeightMethod · 0.80
retryMethod · 0.80
doneMethod · 0.80
verifyNextMethod · 0.80
successMethod · 0.80
AddMethod · 0.65
DoneMethod · 0.65
EqualMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…