diff --git a/src/lib.rs b/src/lib.rs index e5d6dd1..1f3ed63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -276,7 +276,7 @@ impl Node { pubs: Vec::new(), }) } else { - eprintln!("{}", res); + eprintln!("could not create node{}", res); Err(()) } } @@ -368,7 +368,7 @@ impl Node { }; Ok(p) } else { - eprintln!("{}", result); + eprintln!("could not create publisher {}", result); Err(()) } } @@ -491,7 +491,7 @@ where if result == RCL_RET_OK as i32 { Ok(()) } else { - eprintln!("{}", result); + eprintln!("coult not publish {}", result); Err(()) } } @@ -508,7 +508,7 @@ where if result == RCL_RET_OK as i32 { Ok(()) } else { - eprintln!("{}", result); + eprintln!("could not publish native {}", result); Err(()) } } diff --git a/tests/threads.rs b/tests/threads.rs index db6fb03..b547535 100644 --- a/tests/threads.rs +++ b/tests/threads.rs @@ -12,22 +12,25 @@ fn doesnt_crash() -> Result<(), ()> { for c in 0..10 { let mut ths = Vec::new(); - for i in 0..10 { + for i in 0..30 { + // create concurrent nodes that max out the cpu let ctx = ctx.clone(); ths.push(thread::spawn(move || { let mut node = Node::create(ctx, &format!("testnode{}", i), "").unwrap(); - let p = node - .create_publisher::(&format!("/r2r{}", i)) - .unwrap(); - let to_send = std_msgs::msg::String { - data: format!("[node{}]: {}", i, c), - }; + // each with 10 publishers + for _j in 0..10 { + let p = node + .create_publisher::(&format!("/r2r{}", i)) + .unwrap(); + let to_send = std_msgs::msg::String { + data: format!("[node{}]: {}", i, c), + }; - // move publisher to its own thread and publish as fast as we can - thread::spawn(move || { - loop { + // move publisher to its own thread and publish as fast as we can + thread::spawn(move || loop { let res = p.publish(&to_send); + thread::sleep(std::time::Duration::from_millis(1)); match res { Ok(_) => (), Err(_) => { @@ -35,11 +38,14 @@ fn doesnt_crash() -> Result<(), ()> { break; } } - } - }); + }); + } + + // spin to simulate some load + for _j in 0..100 { + node.spin_once(std::time::Duration::from_millis(10)); + } - // wait for 1 sec before dropping - std::thread::sleep(Duration::from_millis(1000)); // println!("all done {}-{}", c, i); })); }