MCPcopy Create free account
hub / github.com/CPChain/chain / TestRandomArrivalImport

Function TestRandomArrivalImport

protocols/cpc/fetcher/fetcher_test.go:401–424  ·  view source on GitHub ↗

Tests that announcements retrieved in a random order are cached and eventually imported when all the gaps are filled in.

(t *testing.T)

Source from the content-addressed store, hash-verified

399// Tests that announcements retrieved in a random order are cached and eventually
400// imported when all the gaps are filled in.
401func TestRandomArrivalImport(t *testing.T) {
402 // Create a chain of blocks to import, and choose one to delay
403 targetBlocks := maxQueueDist
404 hashes, blocks := makeChain(targetBlocks, 0, genesis)
405 skip := targetBlocks / 2
406
407 tester := newTester()
408 headerFetcher := tester.makeHeaderFetcher("valid", blocks, -gatherSlack)
409 bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0)
410
411 // Iteratively announce blocks, skipping one entry
412 imported := make(chan *types.Block, len(hashes)-1)
413 tester.fetcher.importedHook = func(block *types.Block) { imported <- block }
414
415 for i := len(hashes) - 1; i >= 0; i-- {
416 if i != skip {
417 tester.fetcher.Notify("valid", hashes[i], uint64(len(hashes)-i-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher)
418 time.Sleep(time.Millisecond)
419 }
420 }
421 // Finally announce the skipped entry and check full import
422 tester.fetcher.Notify("valid", hashes[skip], uint64(len(hashes)-skip-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher)
423 verifyImportCount(t, imported, len(hashes)-1)
424}
425
426// Tests that direct block enqueues (due to block propagation vs. hash announce)
427// are correctly schedule, filling and import queue gaps.

Callers

nothing calls this directly

Calls 9

makeChainFunction · 0.85
newTesterFunction · 0.85
verifyImportCountFunction · 0.85
makeHeaderFetcherMethod · 0.80
makeBodyFetcherMethod · 0.80
SleepMethod · 0.80
AddMethod · 0.65
NowMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected