fix flaky chain-selection tests (#3948)

This commit is contained in:
Robert Habermeier
2021-09-28 03:43:55 -05:00
committed by GitHub
parent 7da1421baa
commit 408b49268f
@@ -164,6 +164,13 @@ impl Backend for TestBackend {
where where
I: IntoIterator<Item = BackendWriteOp>, I: IntoIterator<Item = BackendWriteOp>,
{ {
let ops: Vec<_> = ops.into_iter().collect();
// Early return if empty because empty writes shouldn't
// trigger wakeups (they happen on an interval)
if ops.is_empty() {
return Ok(())
}
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
for op in ops { for op in ops {
@@ -521,13 +528,13 @@ async fn finalize_block(
block_number: BlockNumber, block_number: BlockNumber,
block_hash: Hash, block_hash: Hash,
) { ) {
let (_, write_tx) = backend.await_next_write(); let (_, write_rx) = backend.await_next_write();
virtual_overseer virtual_overseer
.send(OverseerSignal::BlockFinalized(block_hash, block_number).into()) .send(OverseerSignal::BlockFinalized(block_hash, block_number).into())
.await; .await;
write_tx.await.unwrap(); write_rx.await.unwrap();
} }
fn extract_info_from_chain( fn extract_info_from_chain(
@@ -1701,9 +1708,11 @@ fn approve_nonexistent_has_no_effect() {
.await; .await;
let nonexistent = Hash::repeat_byte(1); let nonexistent = Hash::repeat_byte(1);
approve_block(&mut virtual_overseer, &backend, nonexistent).await; virtual_overseer
.send(FromOverseer::Communication { msg: ChainSelectionMessage::Approved(nonexistent) })
.await;
// a3 is approved, but not a1 or a2. // None are approved.
assert_matches!( assert_matches!(
backend.load_block_entry(&a3_hash).unwrap().unwrap().viability.approval, backend.load_block_entry(&a3_hash).unwrap().unwrap().viability.approval,
Approval::Unapproved Approval::Unapproved