MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestChunkQueue_Discard

Function TestChunkQueue_Discard

statesync/chunks_test.go:180–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestChunkQueue_Discard(t *testing.T) {
181 queue, teardown := setupChunkQueue(t)
182 defer teardown()
183
184 // Add a few chunks to the queue and fetch a couple
185 _, err := queue.Add(&chunk{Height: 3, Format: 1, Index: 0, Chunk: []byte{byte(0)}})
186 require.NoError(t, err)
187 _, err = queue.Add(&chunk{Height: 3, Format: 1, Index: 1, Chunk: []byte{byte(1)}})
188 require.NoError(t, err)
189 _, err = queue.Add(&chunk{Height: 3, Format: 1, Index: 2, Chunk: []byte{byte(2)}})
190 require.NoError(t, err)
191
192 c, err := queue.Next()
193 require.NoError(t, err)
194 assert.EqualValues(t, 0, c.Index)
195 c, err = queue.Next()
196 require.NoError(t, err)
197 assert.EqualValues(t, 1, c.Index)
198
199 // Discarding the first chunk and re-adding it should cause it to be returned
200 // immediately by Next(), before procceeding with chunk 2
201 err = queue.Discard(0)
202 require.NoError(t, err)
203 added, err := queue.Add(&chunk{Height: 3, Format: 1, Index: 0, Chunk: []byte{byte(0)}})
204 require.NoError(t, err)
205 assert.True(t, added)
206 c, err = queue.Next()
207 require.NoError(t, err)
208 assert.EqualValues(t, 0, c.Index)
209 c, err = queue.Next()
210 require.NoError(t, err)
211 assert.EqualValues(t, 2, c.Index)
212
213 // Discard then allocate, add and fetch all chunks
214 for i := uint32(0); i < queue.Size(); i++ {
215 err := queue.Discard(i)
216 require.NoError(t, err)
217 }
218 for i := uint32(0); i < queue.Size(); i++ {
219 _, err := queue.Allocate()
220 require.NoError(t, err)
221 _, err = queue.Add(&chunk{Height: 3, Format: 1, Index: i, Chunk: []byte{byte(i)}})
222 require.NoError(t, err)
223 c, err = queue.Next()
224 require.NoError(t, err)
225 assert.EqualValues(t, i, c.Index)
226 }
227
228 // Discarding a non-existent chunk does nothing.
229 err = queue.Discard(99)
230 require.NoError(t, err)
231
232 // When discard a couple of chunks, we should be able to allocate, add, and fetch them again.
233 err = queue.Discard(3)
234 require.NoError(t, err)
235 err = queue.Discard(1)
236 require.NoError(t, err)
237

Callers

nothing calls this directly

Calls 9

setupChunkQueueFunction · 0.85
DiscardMethod · 0.80
AllocateMethod · 0.80
SizeMethod · 0.65
ErrorMethod · 0.65
EqualMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected