Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix flaky chain-selection tests (#3948)
Browse files Browse the repository at this point in the history
  • Loading branch information
rphmeier authored Sep 28, 2021
1 parent 211a4fc commit fdf3dfd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions node/core/chain-selection/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ impl Backend for TestBackend {
where
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();

for op in ops {
Expand Down Expand Up @@ -521,13 +528,13 @@ async fn finalize_block(
block_number: BlockNumber,
block_hash: Hash,
) {
let (_, write_tx) = backend.await_next_write();
let (_, write_rx) = backend.await_next_write();

virtual_overseer
.send(OverseerSignal::BlockFinalized(block_hash, block_number).into())
.await;

write_tx.await.unwrap();
write_rx.await.unwrap();
}

fn extract_info_from_chain(
Expand Down Expand Up @@ -1701,9 +1708,11 @@ fn approve_nonexistent_has_no_effect() {
.await;

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!(
backend.load_block_entry(&a3_hash).unwrap().unwrap().viability.approval,
Approval::Unapproved
Expand Down

0 comments on commit fdf3dfd

Please sign in to comment.