From f8e07ef5a35affa197b1debd7c10c73992a004df Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Mon, 11 Mar 2019 12:45:45 -0700 Subject: [PATCH] banking_stage_entryfication fails when run as cargo test Add some retry for getting entries from the channel. --- core/src/banking_stage.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 3828f7f1fa..d67edc5958 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -602,23 +602,31 @@ mod tests { poh_service.join().unwrap(); drop(poh_recorder); - // Collect the ledger and feed it to a new bank. - let entries: Vec<_> = entry_receiver - .iter() - .flat_map(|x| x.1.into_iter().map(|e| e.0)) - .collect(); - // same assertion as running through the bank, really... - assert!(entries.len() >= 2); + // Poll the entry_receiver, feeding it into a new bank + // until the balance is what we expect. + let bank = Bank::new(&genesis_block); + for _ in 0..10 { + let entries: Vec<_> = entry_receiver + .iter() + .flat_map(|x| x.1.into_iter().map(|e| e.0)) + .collect(); + + for entry in &entries { + bank.process_transactions(&entry.transactions) + .iter() + .for_each(|x| assert_eq!(*x, Ok(()))); + } + + if bank.get_balance(&alice.pubkey()) == 1 { + break; + } + + sleep(Duration::from_millis(100)); + } // Assert the user holds one lamport, not two. If the stage only outputs one // entry, then the second transaction will be rejected, because it drives // the account balance below zero before the credit is added. - let bank = Bank::new(&genesis_block); - for entry in entries { - bank.process_transactions(&entry.transactions) - .iter() - .for_each(|x| assert_eq!(*x, Ok(()))); - } assert_eq!(bank.get_balance(&alice.pubkey()), 1); }