Threading test more mean

This commit is contained in:
Martin Dahl 2019-08-26 12:57:02 +02:00
parent d0ca455b17
commit 1ed8f3c38c
2 changed files with 24 additions and 18 deletions

View File

@ -276,7 +276,7 @@ impl Node {
pubs: Vec::new(), pubs: Vec::new(),
}) })
} else { } else {
eprintln!("{}", res); eprintln!("could not create node{}", res);
Err(()) Err(())
} }
} }
@ -368,7 +368,7 @@ impl Node {
}; };
Ok(p) Ok(p)
} else { } else {
eprintln!("{}", result); eprintln!("could not create publisher {}", result);
Err(()) Err(())
} }
} }
@ -491,7 +491,7 @@ where
if result == RCL_RET_OK as i32 { if result == RCL_RET_OK as i32 {
Ok(()) Ok(())
} else { } else {
eprintln!("{}", result); eprintln!("coult not publish {}", result);
Err(()) Err(())
} }
} }
@ -508,7 +508,7 @@ where
if result == RCL_RET_OK as i32 { if result == RCL_RET_OK as i32 {
Ok(()) Ok(())
} else { } else {
eprintln!("{}", result); eprintln!("could not publish native {}", result);
Err(()) Err(())
} }
} }

View File

@ -12,22 +12,25 @@ fn doesnt_crash() -> Result<(), ()> {
for c in 0..10 { for c in 0..10 {
let mut ths = Vec::new(); 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(); let ctx = ctx.clone();
ths.push(thread::spawn(move || { ths.push(thread::spawn(move || {
let mut node = Node::create(ctx, &format!("testnode{}", i), "").unwrap(); let mut node = Node::create(ctx, &format!("testnode{}", i), "").unwrap();
let p = node
.create_publisher::<std_msgs::msg::String>(&format!("/r2r{}", i))
.unwrap();
let to_send = std_msgs::msg::String { // each with 10 publishers
data: format!("[node{}]: {}", i, c), for _j in 0..10 {
}; let p = node
.create_publisher::<std_msgs::msg::String>(&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 // move publisher to its own thread and publish as fast as we can
thread::spawn(move || { thread::spawn(move || loop {
loop {
let res = p.publish(&to_send); let res = p.publish(&to_send);
thread::sleep(std::time::Duration::from_millis(1));
match res { match res {
Ok(_) => (), Ok(_) => (),
Err(_) => { Err(_) => {
@ -35,11 +38,14 @@ fn doesnt_crash() -> Result<(), ()> {
break; 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); // println!("all done {}-{}", c, i);
})); }));
} }