Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix approval voting test
  • Loading branch information
davxy committed Mar 16, 2023
commit c2c9e801514747bc9e12a246ff01e98a66007c6a
47 changes: 28 additions & 19 deletions node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use assert_matches::assert_matches;
use async_trait::async_trait;
use parking_lot::Mutex;
use sp_keyring::sr25519::Keyring as Sr25519Keyring;
use sp_keystore::CryptoStore;
use sp_keystore::SyncCryptoStore;
use std::{
pin::Pin,
sync::{
Expand All @@ -65,6 +65,8 @@ use ::test_helpers::{dummy_candidate_receipt, dummy_candidate_receipt_bad_sig};

const SLOT_DURATION_MILLIS: u64 = 5000;

const TIMEOUT: Duration = Duration::from_millis(2000);

#[derive(Clone)]
struct TestSyncOracle {
flag: Arc<AtomicBool>,
Expand Down Expand Up @@ -546,7 +548,6 @@ async fn overseer_recv_with_timeout(
overseer.recv().timeout(timeout).await
}

const TIMEOUT: Duration = Duration::from_millis(2000);
async fn overseer_signal(overseer: &mut VirtualOverseer, signal: OverseerSignal) {
overseer
.send(FromOrchestra::Signal(signal))
Expand Down Expand Up @@ -2415,25 +2416,33 @@ pub async fn handle_double_assignment_import(
recover_available_data(virtual_overseer).await;
fetch_validation_code(virtual_overseer).await;

let first_message = virtual_overseer.recv().await;
let second_message = virtual_overseer.recv().await;
assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ApprovalDistribution(ApprovalDistributionMessage::DistributeAssignment(
_,
c_index
)) => {
assert_eq!(candidate_index, c_index);
}
);

for msg in vec![first_message, second_message].into_iter() {
match msg {
AllMessages::ApprovalDistribution(
ApprovalDistributionMessage::DistributeAssignment(_, c_index),
) => {
assert_eq!(candidate_index, c_index);
},
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx),
) if timeout == PvfExecTimeoutKind::Approval => {
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default())))
.unwrap();
},
_ => panic! {},
assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::CandidateValidation(CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx)) if timeout == PvfExecTimeoutKind::Approval => {
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default())))
.unwrap();
}
}
);

assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ApprovalDistribution(ApprovalDistributionMessage::DistributeApproval(_))
);

assert_matches!(
overseer_recv(virtual_overseer).await,
AllMessages::ApprovalDistribution(ApprovalDistributionMessage::DistributeApproval(_))
);

// Assert that there are no more messages being sent by the subsystem
assert!(overseer_recv(virtual_overseer).timeout(TIMEOUT / 2).await.is_none());
Expand Down