Tests that announcements retrieved in a random order are cached and eventually imported when all the gaps are filled in.
(t *testing.T)
| 399 | // Tests that announcements retrieved in a random order are cached and eventually |
| 400 | // imported when all the gaps are filled in. |
| 401 | func 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. |
nothing calls this directly
no test coverage detected