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

Function TestOverlappingAnnouncements

protocols/cpc/fetcher/fetcher_test.go:332–359  ·  view source on GitHub ↗

Tests that announcements arriving while a previous is being fetched still results in a valid import.

(t *testing.T)

Source from the content-addressed store, hash-verified

330// Tests that announcements arriving while a previous is being fetched still
331// results in a valid import.
332func TestOverlappingAnnouncements(t *testing.T) {
333 // Create a chain of blocks to import
334 targetBlocks := 4 * hashLimit
335 hashes, blocks := makeChain(targetBlocks, 0, genesis)
336
337 tester := newTester()
338 headerFetcher := tester.makeHeaderFetcher("valid", blocks, -gatherSlack)
339 bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0)
340
341 // Iteratively announce blocks, but overlap them continuously
342 overlap := 16
343 imported := make(chan *types.Block, len(hashes)-1)
344 for i := 0; i < overlap; i++ {
345 imported <- nil
346 }
347 tester.fetcher.importedHook = func(block *types.Block) { imported <- block }
348
349 for i := len(hashes) - 2; i >= 0; i-- {
350 tester.fetcher.Notify("valid", hashes[i], uint64(len(hashes)-i-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher)
351 select {
352 case <-imported:
353 case <-time.After(time.Second):
354 t.Fatalf("block %d: import timeout", len(hashes)-i)
355 }
356 }
357 // Wait for all the imports to complete and check count
358 verifyImportCount(t, imported, overlap)
359}
360
361// Tests that announces already being retrieved will not be duplicated.
362func TestPendingDeduplication(t *testing.T) {

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected