Slightly improved tests
This commit is contained in:
parent
beab90c707
commit
ab233a941f
@ -209,6 +209,12 @@ impl<'s, Message> NetworkContext<'s, Message> where Message: Send + Sync + Clone
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send an IO message
|
||||||
|
pub fn message(&self, msg: Message) {
|
||||||
|
self.io.message(NetworkIoMessage::User(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Disable current protocol capability for given peer. If no capabilities left peer gets disconnected.
|
/// Disable current protocol capability for given peer. If no capabilities left peer gets disconnected.
|
||||||
pub fn disable_peer(&self, peer: PeerId) {
|
pub fn disable_peer(&self, peer: PeerId) {
|
||||||
//TODO: remove capability, disconnect if no capabilities left
|
//TODO: remove capability, disconnect if no capabilities left
|
||||||
@ -754,6 +760,7 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
|
|||||||
io.register_timer(DISCOVERY_REFRESH, 7200).expect("Error registering discovery timer");
|
io.register_timer(DISCOVERY_REFRESH, 7200).expect("Error registering discovery timer");
|
||||||
io.register_timer(DISCOVERY_ROUND, 300).expect("Error registering discovery timer");
|
io.register_timer(DISCOVERY_ROUND, 300).expect("Error registering discovery timer");
|
||||||
}
|
}
|
||||||
|
self.maintain_network(io)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stream_hup(&self, io: &IoContext<NetworkIoMessage<Message>>, stream: StreamToken) {
|
fn stream_hup(&self, io: &IoContext<NetworkIoMessage<Message>>, stream: StreamToken) {
|
||||||
|
@ -332,6 +332,7 @@ impl Drop for NodeTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if node url is valid
|
||||||
pub fn is_valid_node_url(url: &str) -> bool {
|
pub fn is_valid_node_url(url: &str) -> bool {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
Node::from_str(url).is_ok()
|
Node::from_str(url).is_ok()
|
||||||
|
@ -74,6 +74,7 @@ impl NetworkProtocolHandler<TestProtocolMessage> for TestProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn connected(&self, io: &NetworkContext<TestProtocolMessage>, peer: &PeerId) {
|
fn connected(&self, io: &NetworkContext<TestProtocolMessage>, peer: &PeerId) {
|
||||||
|
assert!(io.peer_info(*peer).contains("parity"));
|
||||||
if self.drop_session {
|
if self.drop_session {
|
||||||
io.disconnect_peer(*peer)
|
io.disconnect_peer(*peer)
|
||||||
} else {
|
} else {
|
||||||
@ -86,7 +87,8 @@ impl NetworkProtocolHandler<TestProtocolMessage> for TestProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Timer function called after a timeout created with `NetworkContext::timeout`.
|
/// Timer function called after a timeout created with `NetworkContext::timeout`.
|
||||||
fn timeout(&self, _io: &NetworkContext<TestProtocolMessage>, timer: TimerToken) {
|
fn timeout(&self, io: &NetworkContext<TestProtocolMessage>, timer: TimerToken) {
|
||||||
|
io.message(TestProtocolMessage { payload: 22 });
|
||||||
assert_eq!(timer, 0);
|
assert_eq!(timer, 0);
|
||||||
self.got_timeout.store(true, AtomicOrdering::Relaxed);
|
self.got_timeout.store(true, AtomicOrdering::Relaxed);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user