|
@@ -21,7 +21,7 @@ pub struct Node {
|
|
|
|
|
|
impl Node {
|
|
|
pub fn new() -> Result<Node, std::io::Error> {
|
|
|
- let mut child = Command::new("blocktree-node")
|
|
|
+ let mut child = Command::new("btnode")
|
|
|
.stdin(Stdio::piped())
|
|
|
.stdout(Stdio::piped())
|
|
|
.stderr(Stdio::inherit())
|
|
@@ -82,27 +82,32 @@ impl Drop for Node {
|
|
|
mod test {
|
|
|
use super::*;
|
|
|
use ctor::ctor;
|
|
|
- use env_logger;
|
|
|
+ use log::info;
|
|
|
|
|
|
#[ctor]
|
|
|
- fn setup_logging() {
|
|
|
- env_logger::init();
|
|
|
- }
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn node_new() {
|
|
|
- Node::new().unwrap();
|
|
|
+ fn test_init() {
|
|
|
+ use env_logger::{self, Env};
|
|
|
+ env_logger::init_from_env(Env::default().default_filter_or("debug"));
|
|
|
+ info!("Using cargo to install btnode...");
|
|
|
+ let success = Command::new("cargo")
|
|
|
+ .args(["install", "--path", "../btnode"])
|
|
|
+ .status()
|
|
|
+ .expect("failed to invoke cargo")
|
|
|
+ .success();
|
|
|
+ assert!(success, "failed to build btnode");
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
|
fn message_echo() {
|
|
|
let mut node = Node::new().unwrap();
|
|
|
- let payload = "Howdy".to_string();
|
|
|
- node.send(&Message::Echo(payload.clone())).unwrap();
|
|
|
- let reply = node.receive(Duration::from_millis(100)).unwrap();
|
|
|
- let reply_payload = match reply {
|
|
|
- Message::Echo(payload) => Some(payload),
|
|
|
- };
|
|
|
- assert_eq!(Some(payload), reply_payload);
|
|
|
+ for k in 0..7 {
|
|
|
+ let expected = format!("Rep number {}", k);
|
|
|
+ node.send(&Message::Echo(expected.clone())).unwrap();
|
|
|
+ let reply = node.receive(Duration::from_millis(100)).unwrap();
|
|
|
+ let reply_payload = match reply {
|
|
|
+ Message::Echo(actual) => actual,
|
|
|
+ };
|
|
|
+ assert_eq!(expected, reply_payload.as_str());
|
|
|
+ }
|
|
|
}
|
|
|
}
|