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(),
})
} 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(())
}
}

View File

@ -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();
// each with 10 publishers
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
thread::spawn(move || {
loop {
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);
}));
}