mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-31 08:51:57 +00:00
committed by
Toralf Wittner
parent
e5b087d01f
commit
8be45f5318
@@ -254,7 +254,7 @@ pub enum IdentifyEvent {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Identify, IdentifyEvent};
|
||||
use futures::{future, prelude::*};
|
||||
use futures::prelude::*;
|
||||
use libp2p_core::{
|
||||
identity,
|
||||
PeerId,
|
||||
@@ -269,7 +269,6 @@ mod tests {
|
||||
use libp2p_mplex::MplexConfig;
|
||||
use rand::{Rng, thread_rng};
|
||||
use std::{fmt, io};
|
||||
use tokio::runtime::current_thread;
|
||||
|
||||
fn transport() -> (identity::PublicKey, impl Transport<
|
||||
Output = (PeerId, impl StreamMuxer<Substream = impl Send, OutboundSubstream = impl Send, Error = impl Into<io::Error>>),
|
||||
@@ -316,40 +315,28 @@ mod tests {
|
||||
// it will permit the connection to be closed, as defined by
|
||||
// `IdentifyHandler::connection_keep_alive`. Hence the test succeeds if
|
||||
// either `Identified` event arrives correctly.
|
||||
current_thread::Runtime::new().unwrap().block_on(
|
||||
future::poll_fn(move || -> Result<_, io::Error> {
|
||||
loop {
|
||||
match swarm1.poll().unwrap() {
|
||||
Async::Ready(Some(IdentifyEvent::Received { info, .. })) => {
|
||||
assert_eq!(info.public_key, pubkey2);
|
||||
assert_eq!(info.protocol_version, "c");
|
||||
assert_eq!(info.agent_version, "d");
|
||||
assert!(!info.protocols.is_empty());
|
||||
assert!(info.listen_addrs.is_empty());
|
||||
return Ok(Poll::Ready(()))
|
||||
},
|
||||
Async::Ready(Some(IdentifyEvent::Sent { .. })) => (),
|
||||
Async::Ready(e) => panic!("{:?}", e),
|
||||
Async::NotReady => {}
|
||||
futures::executor::block_on(async move {
|
||||
loop {
|
||||
match future::select(swarm1.next(), swarm2.next()).await.factor_second().0 {
|
||||
future::Either::Left(Some(Ok(IdentifyEvent::Received { info, .. }))) => {
|
||||
assert_eq!(info.public_key, pubkey2);
|
||||
assert_eq!(info.protocol_version, "c");
|
||||
assert_eq!(info.agent_version, "d");
|
||||
assert!(!info.protocols.is_empty());
|
||||
assert!(info.listen_addrs.is_empty());
|
||||
return;
|
||||
}
|
||||
|
||||
match swarm2.poll().unwrap() {
|
||||
Async::Ready(Some(IdentifyEvent::Received { info, .. })) => {
|
||||
assert_eq!(info.public_key, pubkey1);
|
||||
assert_eq!(info.protocol_version, "a");
|
||||
assert_eq!(info.agent_version, "b");
|
||||
assert!(!info.protocols.is_empty());
|
||||
assert_eq!(info.listen_addrs.len(), 1);
|
||||
return Ok(Poll::Ready(()))
|
||||
},
|
||||
Async::Ready(Some(IdentifyEvent::Sent { .. })) => (),
|
||||
Async::Ready(e) => panic!("{:?}", e),
|
||||
Async::NotReady => break
|
||||
future::Either::Right(Some(Ok(IdentifyEvent::Received { info, .. }))) => {
|
||||
assert_eq!(info.public_key, pubkey1);
|
||||
assert_eq!(info.protocol_version, "a");
|
||||
assert_eq!(info.agent_version, "b");
|
||||
assert!(!info.protocols.is_empty());
|
||||
assert_eq!(info.listen_addrs.len(), 1);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(Poll::Pending)
|
||||
}))
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user