Fix deadlock in tests that are using with_gossip (#2533)

* fixed gossip related tests deadlock

* cleaning sync tests log

* fixed typo in logs

* send GRANDPA messages without holding validator lock

* Revert "fixed gossip related tests deadlock"

This reverts commit d3fe55e45e32b7ea2e9f05f1c511972c708209ad.
This commit is contained in:
Svyatoslav Nikolsky
2019-05-10 15:14:42 +03:00
committed by Gavin Wood
parent dfbaedd535
commit 42fa5f6209
3 changed files with 23 additions and 33 deletions
-11
View File
@@ -47,7 +47,6 @@ use runtime_primitives::{Justification, ConsensusEngineId};
use crate::service::{network_channel, NetworkChan, NetworkLink, NetworkMsg, NetworkPort, TransactionPool};
use crate::specialization::NetworkSpecialization;
use test_client::{self, AccountKeyring};
use log::debug;
pub use test_client::runtime::{Block, Extrinsic, Hash, Transfer};
pub use test_client::TestClient;
@@ -170,7 +169,6 @@ impl<S: NetworkSpecialization<Block>> Link<Block> for TestLink<S> {
/// with `ImportQueue`.
#[cfg(any(test, feature = "test-helpers"))]
fn synchronized(&self) {
trace!(target: "test_network", "Synchronizing");
drop(self.network_to_protocol_sender.unbounded_send(FromNetworkMsg::Synchronize))
}
}
@@ -241,14 +239,12 @@ impl<S: NetworkSpecialization<Block>> ProtocolChannel<S> {
/// Wait until synchronization response is generated by the protocol.
pub fn wait_sync(&self) -> Result<(), RecvError> {
trace!(target: "test_network", "Waiting for sync");
loop {
match self.protocol_to_network_receiver.receiver().recv() {
Ok(NetworkMsg::Synchronized) => return Ok(()),
Err(error) => return Err(error),
Ok(msg) => self.buffered_messages.lock().push_back(msg),
}
trace!(target: "test_network", "Retrying sync");
}
}
@@ -390,9 +386,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
/// Synchronize with import queue.
#[cfg(any(test, feature = "test-helpers"))]
fn import_queue_sync(&self) {
trace!(target: "test_network", "syncing this queue");
self.import_queue.synchronize();
trace!(target: "test_network", "wating for sync to finish");
let _ = self.net_proto_channel.wait_sync();
}
@@ -728,7 +722,6 @@ pub trait TestNetFactory: Sized {
}
loop {
debug!(target: "test_network", "loop iteration");
// we only deliver Status messages during start
let need_continue = self.route_single(true, None, &|msg| match *msg {
NetworkMsg::Outgoing(_, crate::message::generic::Message::Status(_)) => true,
@@ -755,7 +748,6 @@ pub trait TestNetFactory: Sized {
let mut to_disconnect = HashSet::new();
let peers = self.peers();
for peer in peers {
debug!(target: "test_network", "checking peer");
if let Some(message) = peer.pending_message(message_filter) {
match message {
NetworkMsg::Outgoing(recipient_id, packet) => {
@@ -794,13 +786,10 @@ pub trait TestNetFactory: Sized {
}
}
}
debug!(target: "test_network", "syncing queues");
// make sure that the protocol(s) has processed all messages that have been queued
self.peers().iter().for_each(|peer| peer.import_queue_sync());
debug!(target: "test_network", "queues synced");
had_messages
}