Tests that announcements arriving while a previous is being fetched still results in a valid import.
(t *testing.T)
| 330 | // Tests that announcements arriving while a previous is being fetched still |
| 331 | // results in a valid import. |
| 332 | func 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. |
| 362 | func TestPendingDeduplication(t *testing.T) { |
nothing calls this directly
no test coverage detected