mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 03:02:12 +00:00
* remove tokio_current_thread tests * Review changes: Removed newline Moved uds tokio test crate to top to avoid self and keep with convention of other test crates Removed sleep from uds test and block until all futures are completed.
This commit is contained in:
parent
4a894851ab
commit
490ae980c7
@ -43,7 +43,7 @@ bigint = "4.2"
|
||||
env_logger = "0.5.4"
|
||||
rand = "0.4"
|
||||
structopt = "0.2"
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-io = "0.1"
|
||||
tokio-stdin = "0.1"
|
||||
|
||||
|
@ -29,7 +29,6 @@ libp2p-mplex = { path = "../muxers/mplex" }
|
||||
rand = "0.5"
|
||||
tokio = "0.1"
|
||||
tokio-codec = "0.1"
|
||||
tokio-current-thread = "0.1"
|
||||
tokio-timer = "0.2"
|
||||
assert_matches = "1.3"
|
||||
tokio-mock-task = "0.1"
|
||||
|
@ -129,11 +129,12 @@
|
||||
//! extern crate libp2p_ping;
|
||||
//! extern crate libp2p_core;
|
||||
//! extern crate libp2p_tcp_transport;
|
||||
//! extern crate tokio_current_thread;
|
||||
//! extern crate tokio;
|
||||
//!
|
||||
//! use futures::{Future, Stream};
|
||||
//! use libp2p_ping::{Ping, PingOutput};
|
||||
//! use libp2p_core::Transport;
|
||||
//! use tokio::runtime::current_thread::Runtime;
|
||||
//!
|
||||
//! # fn main() {
|
||||
//! let ping_finished_future = libp2p_tcp_transport::TcpConfig::new()
|
||||
@ -154,7 +155,8 @@
|
||||
//! });
|
||||
//!
|
||||
//! // Runs until the ping arrives.
|
||||
//! tokio_current_thread::block_on_all(ping_finished_future).unwrap();
|
||||
//! let mut rt = Runtime::new().unwrap();
|
||||
//! let _ = rt.block_on(ping_finished_future).unwrap();
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
@ -191,8 +193,6 @@ extern crate tokio;
|
||||
#[cfg(test)]
|
||||
extern crate tokio_codec;
|
||||
#[cfg(test)]
|
||||
extern crate tokio_current_thread;
|
||||
#[cfg(test)]
|
||||
extern crate tokio_timer;
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
|
@ -14,5 +14,5 @@ tokio-io = "0.1"
|
||||
unsigned-varint = { version = "0.2.1", features = ["codec"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
|
@ -45,7 +45,7 @@
|
||||
//! extern crate bytes;
|
||||
//! extern crate futures;
|
||||
//! extern crate multistream_select;
|
||||
//! extern crate tokio_current_thread;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_tcp;
|
||||
//!
|
||||
//! # fn main() {
|
||||
@ -53,6 +53,7 @@
|
||||
//! use multistream_select::dialer_select_proto;
|
||||
//! use futures::{Future, Sink, Stream};
|
||||
//! use tokio_tcp::TcpStream;
|
||||
//! use tokio::runtime::current_thread::Runtime;
|
||||
//!
|
||||
//! #[derive(Debug, Copy, Clone)]
|
||||
//! enum MyProto { Echo, Hello }
|
||||
@ -68,7 +69,8 @@
|
||||
//! dialer_select_proto(connec, protos).map(|r| r.0)
|
||||
//! });
|
||||
//!
|
||||
//! let negotiated_protocol: MyProto = tokio_current_thread::block_on_all(client)
|
||||
//! let mut rt = Runtime::new().unwrap();
|
||||
//! let negotiated_protocol: MyProto = rt.block_on(client)
|
||||
//! .expect("failed to find a protocol");
|
||||
//! println!("negotiated: {:?}", negotiated_protocol);
|
||||
//! # }
|
||||
@ -80,7 +82,7 @@
|
||||
//! extern crate bytes;
|
||||
//! extern crate futures;
|
||||
//! extern crate multistream_select;
|
||||
//! extern crate tokio_current_thread;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_tcp;
|
||||
//!
|
||||
//! # fn main() {
|
||||
@ -88,6 +90,7 @@
|
||||
//! use multistream_select::listener_select_proto;
|
||||
//! use futures::{Future, Sink, Stream};
|
||||
//! use tokio_tcp::TcpListener;
|
||||
//! use tokio::runtime::current_thread::Runtime;
|
||||
//!
|
||||
//! #[derive(Debug, Copy, Clone)]
|
||||
//! enum MyProto { Echo, Hello }
|
||||
@ -108,7 +111,8 @@
|
||||
//! Ok(())
|
||||
//! });
|
||||
//!
|
||||
//! tokio_current_thread::block_on_all(server).expect("failed to run server");
|
||||
//! let mut rt = Runtime::new().unwrap();
|
||||
//! let _ = rt.block_on(server).expect("failed to run server");
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
|
@ -183,8 +183,9 @@ impl<T: AsyncWrite> Future for DialerFuture<T> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::{TcpListener, TcpStream};
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
@ -210,7 +211,8 @@ mod tests {
|
||||
dialer.send(DialerToListenerMessage::ProtocolRequest { name: p })
|
||||
});
|
||||
|
||||
match tokio_current_thread::block_on_all(server.join(client)) {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
match rt.block_on(server.join(client)) {
|
||||
Err(MultistreamSelectError::WrongProtocolName) => (),
|
||||
_ => panic!(),
|
||||
}
|
||||
|
@ -225,8 +225,9 @@ impl<T: AsyncRead + AsyncWrite> Future for ListenerFuture<T> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::{TcpListener, TcpStream};
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
@ -252,7 +253,8 @@ mod tests {
|
||||
.from_err()
|
||||
.and_then(move |stream| Dialer::new(stream));
|
||||
|
||||
match tokio_current_thread::block_on_all(server.join(client)) {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
match rt.block_on(server.join(client)) {
|
||||
Err(MultistreamSelectError::WrongProtocolName) => (),
|
||||
_ => panic!(),
|
||||
}
|
||||
|
@ -22,9 +22,10 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::{TcpListener, TcpStream};
|
||||
use bytes::Bytes;
|
||||
use dialer_select::{dialer_select_proto_parallel, dialer_select_proto_serial};
|
||||
@ -69,8 +70,8 @@ fn negotiate_with_self_succeeds() {
|
||||
assert_eq!(proto, "/hello/1.0.0");
|
||||
Ok(())
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(server.join(client)).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(server.join(client)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -100,9 +101,9 @@ fn select_proto_basic() {
|
||||
].into_iter();
|
||||
dialer_select_proto(connec, protos).map(|r| r.0)
|
||||
});
|
||||
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let (dialer_chosen, listener_chosen) =
|
||||
tokio_current_thread::block_on_all(client.join(server)).unwrap();
|
||||
rt.block_on(client.join(server)).unwrap();
|
||||
assert_eq!(dialer_chosen, 3);
|
||||
assert_eq!(listener_chosen, 1);
|
||||
}
|
||||
@ -134,8 +135,8 @@ fn no_protocol_found() {
|
||||
].into_iter();
|
||||
dialer_select_proto(connec, protos).map(|r| r.0)
|
||||
});
|
||||
|
||||
match tokio_current_thread::block_on_all(client.join(server)) {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
match rt.block_on(client.join(server)) {
|
||||
Err(ProtocolChoiceError::NoProtocolFound) => (),
|
||||
_ => panic!(),
|
||||
}
|
||||
@ -169,8 +170,9 @@ fn select_proto_parallel() {
|
||||
dialer_select_proto_parallel(connec, protos).map(|r| r.0)
|
||||
});
|
||||
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let (dialer_chosen, listener_chosen) =
|
||||
tokio_current_thread::block_on_all(client.join(server)).unwrap();
|
||||
rt.block_on(client.join(server)).unwrap();
|
||||
assert_eq!(dialer_chosen, 3);
|
||||
assert_eq!(listener_chosen, 1);
|
||||
}
|
||||
@ -200,8 +202,9 @@ fn select_proto_serial() {
|
||||
dialer_select_proto_serial(connec, protos).map(|r| r.0)
|
||||
});
|
||||
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let (dialer_chosen, listener_chosen) =
|
||||
tokio_current_thread::block_on_all(client.join(server)).unwrap();
|
||||
rt.block_on(client.join(server)).unwrap();
|
||||
assert_eq!(dialer_chosen, 3);
|
||||
assert_eq!(listener_chosen, 1);
|
||||
}
|
||||
|
@ -17,4 +17,4 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }
|
||||
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
|
@ -23,7 +23,7 @@ extern crate futures;
|
||||
extern crate libp2p_mplex as multiplex;
|
||||
extern crate libp2p_core as swarm;
|
||||
extern crate libp2p_tcp_transport as tcp;
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_io;
|
||||
|
||||
use futures::future::Future;
|
||||
@ -33,6 +33,7 @@ use std::thread;
|
||||
use swarm::{muxing, Transport};
|
||||
use tcp::TcpConfig;
|
||||
use tokio_io::codec::length_delimited::Framed;
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
|
||||
#[test]
|
||||
fn client_to_server_outbound() {
|
||||
@ -67,7 +68,8 @@ fn client_to_server_outbound() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
});
|
||||
|
||||
let transport = TcpConfig::new().with_upgrade(multiplex::MplexConfig::new());
|
||||
@ -80,7 +82,8 @@ fn client_to_server_outbound() {
|
||||
.and_then(|server| server.send("hello world".into()))
|
||||
.map(|_| ());
|
||||
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
bg_thread.join().unwrap();
|
||||
}
|
||||
|
||||
@ -117,7 +120,8 @@ fn client_to_server_inbound() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
});
|
||||
|
||||
let transport = TcpConfig::new().with_upgrade(multiplex::MplexConfig::new());
|
||||
@ -130,6 +134,7 @@ fn client_to_server_inbound() {
|
||||
.and_then(|server| server.send("hello world".into()))
|
||||
.map(|_| ());
|
||||
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
bg_thread.join().unwrap();
|
||||
}
|
||||
|
@ -22,4 +22,4 @@ void = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
|
@ -211,8 +211,9 @@ fn parse_proto_msg(msg: BytesMut) -> Result<(IdentifyInfo, Multiaddr), IoError>
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate libp2p_tcp_transport;
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::libp2p_tcp_transport::TcpConfig;
|
||||
use futures::{Future, Stream};
|
||||
use libp2p_core::{PublicKey, Transport};
|
||||
@ -255,8 +256,8 @@ mod tests {
|
||||
),
|
||||
_ => panic!(),
|
||||
});
|
||||
|
||||
let _ = tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
});
|
||||
|
||||
let transport = TcpConfig::new().with_upgrade(IdentifyProtocolConfig);
|
||||
@ -291,8 +292,8 @@ mod tests {
|
||||
}
|
||||
_ => panic!(),
|
||||
});
|
||||
|
||||
let _ = tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
bg_thread.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -30,4 +30,4 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
rand = "0.4.2"
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
|
@ -409,7 +409,7 @@ fn proto_to_msg(mut message: protobuf_structs::dht::Message) -> Result<KadMsg, I
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate libp2p_tcp_transport;
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
|
||||
use self::libp2p_tcp_transport::TcpConfig;
|
||||
use futures::{Future, Sink, Stream};
|
||||
@ -418,6 +418,8 @@ mod tests {
|
||||
use protocol::{KadConnectionType, KadMsg, KademliaProtocolConfig, KadPeer};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
|
||||
|
||||
#[test]
|
||||
fn correct_transfer() {
|
||||
@ -494,8 +496,8 @@ mod tests {
|
||||
assert_eq!(recv_msg.unwrap(), msg_server);
|
||||
()
|
||||
});
|
||||
|
||||
let _ = tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
});
|
||||
|
||||
let transport = TcpConfig::new().with_upgrade(KademliaProtocolConfig);
|
||||
@ -505,8 +507,8 @@ mod tests {
|
||||
.unwrap_or_else(|_| panic!())
|
||||
.and_then(|proto| proto.send(msg_client))
|
||||
.map(|_| ());
|
||||
|
||||
let _ = tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
bg_thread.join().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ tokio-io = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
|
@ -53,11 +53,12 @@
|
||||
//! extern crate libp2p_ping;
|
||||
//! extern crate libp2p_core;
|
||||
//! extern crate libp2p_tcp_transport;
|
||||
//! extern crate tokio_current_thread;
|
||||
//! extern crate tokio;
|
||||
//!
|
||||
//! use futures::{Future, Stream};
|
||||
//! use libp2p_ping::{Ping, PingOutput};
|
||||
//! use libp2p_core::Transport;
|
||||
//! use tokio::runtime::current_thread::Runtime;
|
||||
//!
|
||||
//! # fn main() {
|
||||
//! let ping_finished_future = libp2p_tcp_transport::TcpConfig::new()
|
||||
@ -75,7 +76,8 @@
|
||||
//! });
|
||||
//!
|
||||
//! // Runs until the ping arrives.
|
||||
//! tokio_current_thread::block_on_all(ping_finished_future).unwrap();
|
||||
//! let mut rt = Runtime::new().unwrap();
|
||||
//! let _ = rt.block_on(ping_finished_future).unwrap();
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
@ -391,9 +393,10 @@ impl Encoder for Codec {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::TcpListener;
|
||||
use self::tokio_tcp::TcpStream;
|
||||
use super::{Ping, PingOutput};
|
||||
@ -440,8 +443,8 @@ mod tests {
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.map(|_| ());
|
||||
|
||||
tokio_current_thread::block_on_all(server.select(client).map_err(|_| panic!())).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(server.select(client).map_err(|_| panic!())).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -489,7 +492,7 @@ mod tests {
|
||||
},
|
||||
_ => unreachable!(),
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(server.select(client)).unwrap_or_else(|_| panic!());
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(server.select(client)).unwrap_or_else(|_| panic!());
|
||||
}
|
||||
}
|
||||
|
@ -40,5 +40,5 @@ aes-all = ["aesni", "lazy_static"]
|
||||
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
|
@ -119,8 +119,9 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::TcpListener;
|
||||
use self::tokio_tcp::TcpStream;
|
||||
use stream_cipher::{ctr, Cipher};
|
||||
@ -164,8 +165,9 @@ mod tests {
|
||||
|
||||
let data_sent = encoder.send(BytesMut::from(data.to_vec())).from_err();
|
||||
let data_received = decoder.into_future().map(|(n, _)| n).map_err(|(e, _)| e);
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
let (_, decoded) = tokio_current_thread::block_on_all(data_sent.join(data_received))
|
||||
let (_, decoded) = rt.block_on(data_sent.join(data_received))
|
||||
.map_err(|_| ())
|
||||
.unwrap();
|
||||
assert_eq!(&decoded.unwrap()[..], &data[..]);
|
||||
@ -223,7 +225,8 @@ mod tests {
|
||||
.and_then(|server| server.into_future().map_err(|(e, _)| e.into()))
|
||||
.map(|recved| recved.0.unwrap().to_vec());
|
||||
|
||||
let received = tokio_current_thread::block_on_all(fin).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let received = rt.block_on(fin).unwrap();
|
||||
assert_eq!(received, data);
|
||||
}
|
||||
|
||||
|
@ -646,8 +646,9 @@ where ::hmac::Hmac<D>: Clone {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
extern crate tokio_tcp;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use self::tokio_tcp::TcpListener;
|
||||
use self::tokio_tcp::TcpStream;
|
||||
use super::handshake;
|
||||
@ -712,8 +713,8 @@ mod tests {
|
||||
let client = TcpStream::connect(&listener_addr)
|
||||
.map_err(|e| e.into())
|
||||
.and_then(move |stream| handshake(stream, key2));
|
||||
|
||||
tokio_current_thread::block_on_all(server.join(client)).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(server.join(client)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -30,7 +30,7 @@
|
||||
//!
|
||||
//! ```no_run
|
||||
//! extern crate futures;
|
||||
//! extern crate tokio_current_thread;
|
||||
//! extern crate tokio;
|
||||
//! extern crate tokio_io;
|
||||
//! extern crate libp2p_core;
|
||||
//! extern crate libp2p_secio;
|
||||
@ -42,6 +42,7 @@
|
||||
//! use libp2p_core::{Multiaddr, Transport, upgrade};
|
||||
//! use libp2p_tcp_transport::TcpConfig;
|
||||
//! use tokio_io::io::write_all;
|
||||
//! use tokio::runtime::current_thread::Runtime;
|
||||
//!
|
||||
//! let transport = TcpConfig::new()
|
||||
//! .with_upgrade({
|
||||
@ -63,7 +64,8 @@
|
||||
//! write_all(connection, "hello world")
|
||||
//! });
|
||||
//!
|
||||
//! tokio_current_thread::block_on_all(future).unwrap();
|
||||
//! let mut rt = Runtime::new().unwrap();
|
||||
//! let _ = rt.block_on(future).unwrap();
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -14,3 +14,4 @@ tokio-io = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../../transports/tcp" }
|
||||
tokio = "0.1"
|
@ -14,4 +14,4 @@ tokio-io = "0.1"
|
||||
tokio-tcp = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
|
@ -47,9 +47,6 @@ extern crate tk_listen;
|
||||
extern crate tokio_io;
|
||||
extern crate tokio_tcp;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate tokio_current_thread;
|
||||
|
||||
use futures::{future, future::FutureResult, prelude::*, Async, Poll};
|
||||
use multiaddr::{Protocol, Multiaddr, ToMultiaddr};
|
||||
use std::fmt;
|
||||
@ -394,6 +391,8 @@ impl Drop for TcpTransStream {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tokio;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use super::{multiaddr_to_socketaddr, TcpConfig};
|
||||
use futures::stream::Stream;
|
||||
use futures::Future;
|
||||
@ -401,7 +400,6 @@ mod tests {
|
||||
use std;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use swarm::Transport;
|
||||
use tokio_current_thread;
|
||||
use tokio_io;
|
||||
|
||||
#[test]
|
||||
@ -460,6 +458,8 @@ mod tests {
|
||||
std::thread::spawn(move || {
|
||||
let addr = "/ip4/127.0.0.1/tcp/12345".parse::<Multiaddr>().unwrap();
|
||||
let tcp = TcpConfig::new();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let handle = rt.handle();
|
||||
let listener = tcp.listen_on(addr).unwrap().0.for_each(|(sock, _)| {
|
||||
sock.and_then(|sock| {
|
||||
// Define what to do with the socket that just connected to us
|
||||
@ -469,13 +469,14 @@ mod tests {
|
||||
.map_err(|err| panic!("IO error {:?}", err));
|
||||
|
||||
// Spawn the future as a concurrent task
|
||||
tokio_current_thread::spawn(handle_conn);
|
||||
handle.spawn(handle_conn).unwrap();
|
||||
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(listener).unwrap();
|
||||
rt.block_on(listener).unwrap();
|
||||
rt.run().unwrap();
|
||||
});
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
let addr = "/ip4/127.0.0.1/tcp/12345".parse::<Multiaddr>().unwrap();
|
||||
@ -488,8 +489,8 @@ mod tests {
|
||||
Ok(())
|
||||
});
|
||||
// Execute the future in our event loop
|
||||
tokio_current_thread::block_on_all(action).unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(action).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -13,5 +13,5 @@ tokio-uds = "0.2"
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "emscripten")))'.dev-dependencies]
|
||||
tempfile = "3.0"
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
tokio-io = "0.1"
|
||||
|
@ -56,9 +56,9 @@ extern crate tokio_uds;
|
||||
#[cfg(test)]
|
||||
extern crate tempfile;
|
||||
#[cfg(test)]
|
||||
extern crate tokio_current_thread;
|
||||
#[cfg(test)]
|
||||
extern crate tokio_io;
|
||||
#[cfg(test)]
|
||||
extern crate tokio;
|
||||
|
||||
use futures::future::{self, Future, FutureResult};
|
||||
use futures::stream::Stream;
|
||||
@ -164,6 +164,7 @@ fn multiaddr_to_path(addr: &Multiaddr) -> Result<PathBuf, ()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
use super::{multiaddr_to_path, UdsConfig};
|
||||
use futures::stream::Stream;
|
||||
use futures::Future;
|
||||
@ -171,7 +172,6 @@ mod tests {
|
||||
use std::{self, borrow::Cow, path::Path};
|
||||
use libp2p_core::Transport;
|
||||
use tempfile;
|
||||
use tokio_current_thread;
|
||||
use tokio_io;
|
||||
|
||||
#[test]
|
||||
@ -194,7 +194,6 @@ mod tests {
|
||||
#[test]
|
||||
fn communicating_between_dialer_and_listener() {
|
||||
use std::io::Write;
|
||||
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let socket = temp_dir.path().join("socket");
|
||||
let addr = Multiaddr::from(Protocol::Unix(Cow::Owned(socket.to_string_lossy().into_owned())));
|
||||
@ -202,6 +201,9 @@ mod tests {
|
||||
|
||||
std::thread::spawn(move || {
|
||||
let tcp = UdsConfig::new();
|
||||
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let handle = rt.handle();
|
||||
let listener = tcp.listen_on(addr2).unwrap().0.for_each(|(sock, _)| {
|
||||
sock.and_then(|sock| {
|
||||
// Define what to do with the socket that just connected to us
|
||||
@ -211,13 +213,13 @@ mod tests {
|
||||
.map_err(|err| panic!("IO error {:?}", err));
|
||||
|
||||
// Spawn the future as a concurrent task
|
||||
tokio_current_thread::spawn(handle_conn);
|
||||
|
||||
handle.spawn(handle_conn).unwrap();
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
|
||||
tokio_current_thread::block_on_all(listener).unwrap();
|
||||
rt.block_on(listener).unwrap();
|
||||
rt.run().unwrap();
|
||||
});
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
let tcp = UdsConfig::new();
|
||||
@ -229,8 +231,8 @@ mod tests {
|
||||
Ok(())
|
||||
});
|
||||
// Execute the future in our event loop
|
||||
tokio_current_thread::block_on_all(action).unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(action).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -22,4 +22,4 @@ stdweb = { version = "0.1.3", default-features = false }
|
||||
|
||||
[target.'cfg(not(target_os = "emscripten"))'.dev-dependencies]
|
||||
libp2p-tcp-transport = { path = "../tcp" }
|
||||
tokio-current-thread = "0.1"
|
||||
tokio = "0.1"
|
||||
|
@ -259,7 +259,8 @@ fn client_addr_to_ws(client_addr: &Multiaddr, is_wss: bool) -> String {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate libp2p_tcp_transport as tcp;
|
||||
extern crate tokio_current_thread;
|
||||
extern crate tokio;
|
||||
use self::tokio::runtime::current_thread::Runtime;
|
||||
use futures::{Future, Stream};
|
||||
use multiaddr::Multiaddr;
|
||||
use swarm::Transport;
|
||||
@ -285,7 +286,8 @@ mod tests {
|
||||
.select(dialer)
|
||||
.map_err(|(e, _)| e)
|
||||
.and_then(|(_, n)| n);
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -308,7 +310,9 @@ mod tests {
|
||||
.select(dialer)
|
||||
.map_err(|(e, _)| e)
|
||||
.and_then(|(_, n)| n);
|
||||
tokio_current_thread::block_on_all(future).unwrap();
|
||||
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
let _ = rt.block_on(future).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user