mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 07:58:00 +00:00
test: add unit test to catch missing distribution to subsystems faster (#2495)
* test: add unit test to catch missing distribution to subsystems faster * add a simple count * introduce proc macro to generate dispatch type * refactor * refactor * chore: add license * fixup unit test * fixup merge * better errors * better fmt * fix error spans * better docs * better error messages * ui test foo * Update node/subsystem/dispatch-gen/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update node/network/bridge/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update node/subsystem/Cargo.toml Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update node/subsystem/dispatch-gen/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update node/subsystem/dispatch-gen/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update node/network/bridge/src/lib.rs Co-authored-by: Andronik Ordian <write@reusable.software> * fix compilation * use find_map * drop the silly 2, use _inner instead * Update node/network/bridge/src/lib.rs Co-authored-by: Andronik Ordian <write@reusable.software> * Update node/subsystem/dispatch-gen/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * nail deps down * more into() * flatten * missing use statement * fix messages order Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
committed by
GitHub
parent
69734bb8ed
commit
31327eb0c7
@@ -28,10 +28,8 @@ use polkadot_subsystem::{
|
||||
SubsystemResult, jaeger,
|
||||
};
|
||||
use polkadot_subsystem::messages::{
|
||||
NetworkBridgeMessage, AllMessages, AvailabilityDistributionMessage,
|
||||
BitfieldDistributionMessage, PoVDistributionMessage, StatementDistributionMessage,
|
||||
CollatorProtocolMessage, ApprovalDistributionMessage, NetworkBridgeEvent,
|
||||
AvailabilityRecoveryMessage,
|
||||
NetworkBridgeMessage, AllMessages,
|
||||
CollatorProtocolMessage, NetworkBridgeEvent,
|
||||
};
|
||||
use polkadot_primitives::v1::{Hash, BlockNumber};
|
||||
use polkadot_node_network_protocol::{
|
||||
@@ -565,35 +563,7 @@ async fn dispatch_validation_events_to_all<I>(
|
||||
I: IntoIterator<Item = NetworkBridgeEvent<protocol_v1::ValidationProtocol>>,
|
||||
I::IntoIter: Send,
|
||||
{
|
||||
let messages_for = |event: NetworkBridgeEvent<protocol_v1::ValidationProtocol>| {
|
||||
let av_d = std::iter::once(event.focus().ok().map(|m| AllMessages::AvailabilityDistribution(
|
||||
AvailabilityDistributionMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
let b = std::iter::once(event.focus().ok().map(|m| AllMessages::BitfieldDistribution(
|
||||
BitfieldDistributionMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
let p = std::iter::once(event.focus().ok().map(|m| AllMessages::PoVDistribution(
|
||||
PoVDistributionMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
let s = std::iter::once(event.focus().ok().map(|m| AllMessages::StatementDistribution(
|
||||
StatementDistributionMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
let ap = std::iter::once(event.focus().ok().map(|m| AllMessages::ApprovalDistribution(
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
let av_r = std::iter::once(event.focus().ok().map(|m| AllMessages::AvailabilityRecovery(
|
||||
AvailabilityRecoveryMessage::NetworkBridgeUpdateV1(m)
|
||||
)));
|
||||
|
||||
av_d.chain(b).chain(p).chain(s).chain(ap).chain(av_r).filter_map(|x| x)
|
||||
};
|
||||
|
||||
ctx.send_messages(events.into_iter().flat_map(messages_for)).await
|
||||
ctx.send_messages(events.into_iter().flat_map(AllMessages::dispatch_iter)).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(events, ctx), fields(subsystem = LOG_TARGET))]
|
||||
@@ -635,8 +605,12 @@ mod tests {
|
||||
|
||||
use polkadot_subsystem::{ActiveLeavesUpdate, FromOverseer, OverseerSignal};
|
||||
use polkadot_subsystem::messages::{
|
||||
StatementDistributionMessage, BitfieldDistributionMessage,
|
||||
AvailabilityDistributionMessage,
|
||||
AvailabilityRecoveryMessage,
|
||||
ApprovalDistributionMessage,
|
||||
BitfieldDistributionMessage,
|
||||
PoVDistributionMessage,
|
||||
StatementDistributionMessage
|
||||
};
|
||||
use polkadot_node_subsystem_test_helpers::{
|
||||
SingleItemSink, SingleItemStream, TestSubsystemContextHandle,
|
||||
@@ -818,6 +792,15 @@ mod tests {
|
||||
event: NetworkBridgeEvent<protocol_v1::ValidationProtocol>,
|
||||
virtual_overseer: &mut TestSubsystemContextHandle<NetworkBridgeMessage>,
|
||||
) {
|
||||
// Ordering must match the enum variant order
|
||||
// in `AllMessages`.
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::StatementDistribution(
|
||||
StatementDistributionMessage::NetworkBridgeUpdateV1(e)
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::AvailabilityDistribution(
|
||||
@@ -825,6 +808,13 @@ mod tests {
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::AvailabilityRecovery(
|
||||
AvailabilityRecoveryMessage::NetworkBridgeUpdateV1(e)
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::BitfieldDistribution(
|
||||
@@ -839,26 +829,12 @@ mod tests {
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::StatementDistribution(
|
||||
StatementDistributionMessage::NetworkBridgeUpdateV1(e)
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::ApprovalDistribution(
|
||||
ApprovalDistributionMessage::NetworkBridgeUpdateV1(e)
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
|
||||
assert_matches!(
|
||||
virtual_overseer.recv().await,
|
||||
AllMessages::AvailabilityRecovery(
|
||||
AvailabilityRecoveryMessage::NetworkBridgeUpdateV1(e)
|
||||
) if e == event.focus().expect("could not focus message")
|
||||
);
|
||||
}
|
||||
|
||||
async fn assert_sends_collation_event_to_all(
|
||||
@@ -1546,4 +1522,38 @@ mod tests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spread_event_to_subsystems_is_up_to_date() {
|
||||
// Number of subsystems expected to be interested in a network event,
|
||||
// and hence the network event broadcasted to.
|
||||
const EXPECTED_COUNT: usize = 6;
|
||||
|
||||
let mut cnt = 0_usize;
|
||||
for msg in AllMessages::dispatch_iter(NetworkBridgeEvent::PeerDisconnected(PeerId::random())) {
|
||||
match msg {
|
||||
AllMessages::CandidateValidation(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::CandidateBacking(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::CandidateSelection(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::ChainApi(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::CollatorProtocol(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::StatementDistribution(_) => { cnt += 1; }
|
||||
AllMessages::AvailabilityDistribution(_) => { cnt += 1; }
|
||||
AllMessages::AvailabilityRecovery(_) => { cnt += 1; }
|
||||
AllMessages::BitfieldDistribution(_) => { cnt += 1; }
|
||||
AllMessages::BitfieldSigning(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::Provisioner(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::PoVDistribution(_) => { cnt += 1; }
|
||||
AllMessages::RuntimeApi(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::AvailabilityStore(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::NetworkBridge(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::CollationGeneration(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::ApprovalVoting(_) => unreachable!("Not interested in network events"),
|
||||
AllMessages::ApprovalDistribution(_) => { cnt += 1; }
|
||||
// Add variants here as needed, `{ cnt += 1; }` for those that need to be
|
||||
// notified, `unreachable!()` for those that should not.
|
||||
}
|
||||
}
|
||||
assert_eq!(cnt, EXPECTED_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user