This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
client/finality-grandpa: Add regression test for observer polling network #4778
Closed
+97
−7
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -370,3 +370,84 @@ where | |||
| Future::poll(Pin::new(&mut self.network), cx) | ||||
| } | ||||
| } | ||||
|
|
||||
| #[cfg(test)] | ||||
| mod tests { | ||||
| use super::*; | ||||
|
|
||||
| use crate::{aux_schema, communication::tests::{Event, make_test_network}}; | ||||
| use substrate_test_runtime_client::{TestClientBuilder, TestClientBuilderExt}; | ||||
| use sc_network::PeerId; | ||||
|
|
||||
| use futures::executor::{self, ThreadPool}; | ||||
|
|
||||
| #[test] | ||||
| /// Ensure `Future` implementation of `ObserverWork` is polling its `NetworkBridge`. Regression | ||||
NikVolf marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| /// test for bug introduced in d4fbb897c and fixed in b7af8b339. | ||||
| /// | ||||
| /// When polled, `NetworkBridge` forwards reputation change requests from the `GossipValidator` | ||||
| /// to the underlying `dyn Network`. This test triggers a reputation change by calling | ||||
| /// `GossipValidator::validate` with an invalid gossip message. After polling the `ObserverWork` | ||||
| /// which should poll the `NetworkBridge`, the reputation change should be forwarded to the test | ||||
| /// network. | ||||
| fn observer_work_polls_underlying_network_bridge() { | ||||
| let thread_pool = ThreadPool::new().unwrap(); | ||||
|
|
||||
| // Create a test network. | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| let (tester_fut, _network) = make_test_network(&thread_pool); | ||||
| let mut tester = executor::block_on(tester_fut); | ||||
|
|
||||
| // Create an observer. | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| let (client, backend) = { | ||||
| let builder = TestClientBuilder::with_default_backend(); | ||||
| let backend = builder.backend(); | ||||
| let (client, _) = builder.build_with_longest_chain(); | ||||
| (Arc::new(client), backend) | ||||
| }; | ||||
|
|
||||
| let persistent_data = aux_schema::load_persistent( | ||||
| &*backend, | ||||
| client.chain_info().genesis_hash, | ||||
| 0, | ||||
| || Ok(vec![]), | ||||
| ).unwrap(); | ||||
|
|
||||
| let (_tx, voter_command_rx) = mpsc::unbounded(); | ||||
| let observer = ObserverWork::new( | ||||
| client, | ||||
| tester.net_handle.clone(), | ||||
| persistent_data, | ||||
| None, | ||||
| voter_command_rx, | ||||
| ); | ||||
|
|
||||
| // Trigger a reputation change through the gossip validator. | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| let peer_id = PeerId::random(); | ||||
| tester.trigger_gossip_validator_reputation_change(&peer_id); | ||||
|
|
||||
| executor::block_on(async move { | ||||
| // Ignore initial event stream request by gossip engine. | ||||
| match tester.events.next().now_or_never() { | ||||
| Some(Some(Event::EventStream(_))) => {}, | ||||
| _ => panic!("expected event stream request"), | ||||
| }; | ||||
|
|
||||
| assert!( | ||||
| tester.events.next().now_or_never().is_none(), | ||||
| "expect no further network events", | ||||
| ); | ||||
|
|
||||
| // Poll the observer once and have it forward the reputation change from the gossip | ||||
| // validator to the test network. | ||||
| assert!(observer.now_or_never().is_none()); | ||||
|
|
||||
| match tester.events.next().now_or_never() { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| Some(Some(Event::Report(_, _))) => {}, | ||||
| _ => panic!("expected test network to receive reputation change event"), | ||||
| }; | ||||
| }); | ||||
| } | ||||
| } | ||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put bellow the comment.