Skip to content

Commit 2f92580

Browse files
committed
Fix tests
1 parent e71ac74 commit 2f92580

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

commons/zenoh-shm/tests/common/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414

1515
use std::{
16+
fmt::Debug,
1617
sync::{atomic::AtomicBool, Arc},
1718
thread::JoinHandle,
1819
};
@@ -35,17 +36,21 @@ pub fn validate_memory(mem1: &mut [u8], mem2: &[u8]) {
3536
}
3637
}
3738

38-
pub fn execute_concurrent<TaskFun>(concurrent_tasks: usize, iterations: usize, task_fun: TaskFun)
39-
where
40-
TaskFun: Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static,
39+
pub fn execute_concurrent<TaskFun, Terror>(
40+
concurrent_tasks: usize,
41+
iterations: usize,
42+
task_fun: TaskFun,
43+
) where
44+
TaskFun: Fn(usize, usize) -> Result<(), Terror> + Clone + Send + Sync + 'static,
45+
Terror: Debug,
4146
{
4247
let mut tasks = vec![];
4348
for task_index in 0..concurrent_tasks {
4449
let c_task_fun = task_fun.clone();
4550
let task_handle = std::thread::spawn(move || {
4651
for iteration in 0..iterations {
4752
if let Err(e) = c_task_fun(task_index, iteration) {
48-
panic!("task {task_index}: iteration {iteration}: {e}")
53+
panic!("task {task_index}: iteration {iteration}: {:?}", e)
4954
}
5055
}
5156
});

commons/zenoh-shm/tests/metadata.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@
1515
use std::{ops::Deref, sync::atomic::Ordering::Relaxed, time::Duration};
1616

1717
use rand::Rng;
18-
use zenoh_core::bail;
18+
use tracing::error;
1919
use zenoh_result::ZResult;
2020

2121
pub mod common;
2222
use common::{execute_concurrent, CpuLoad};
2323
use zenoh_shm::{
24+
api::provider::types::ZAllocError,
2425
metadata::{
2526
descriptor::MetadataDescriptor, storage::GLOBAL_METADATA_STORAGE,
2627
subscription::GLOBAL_METADATA_SUBSCRIPTION,
2728
},
2829
watchdog::{confirmator::GLOBAL_CONFIRMATOR, validator::GLOBAL_VALIDATOR},
2930
};
3031

31-
fn metadata_alloc_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static {
32-
|_task_index: usize, _iteration: usize| -> ZResult<()> {
32+
fn metadata_alloc_fn(
33+
) -> impl Fn(usize, usize) -> Result<(), ZAllocError> + Clone + Send + Sync + 'static {
34+
|_task_index: usize, _iteration: usize| {
3335
let _allocated_metadata = GLOBAL_METADATA_STORAGE.read().allocate()?;
3436
Ok(())
3537
}
@@ -45,7 +47,8 @@ fn metadata_alloc_concurrent() {
4547
execute_concurrent(100, 1000, metadata_alloc_fn());
4648
}
4749

48-
fn metadata_link_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static {
50+
fn metadata_link_fn(
51+
) -> impl Fn(usize, usize) -> Result<(), ZAllocError> + Clone + Send + Sync + 'static {
4952
|_task_index: usize, _iteration: usize| {
5053
let allocated_metadata = GLOBAL_METADATA_STORAGE.read().allocate()?;
5154
let descr = MetadataDescriptor::from(allocated_metadata.deref());
@@ -64,8 +67,8 @@ fn metadata_link_concurrent() {
6467
execute_concurrent(100, 1000, metadata_link_fn());
6568
}
6669

67-
fn metadata_link_failure_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static
68-
{
70+
fn metadata_link_failure_fn(
71+
) -> impl Fn(usize, usize) -> Result<(), ZAllocError> + Clone + Send + Sync + 'static {
6972
|_task_index: usize, _iteration: usize| {
7073
let allocated_metadata = GLOBAL_METADATA_STORAGE.read().allocate()?;
7174
let descr = MetadataDescriptor::from(allocated_metadata.deref());
@@ -93,7 +96,7 @@ fn metadata_link_failure_concurrent() {
9396
}
9497

9598
fn metadata_check_memory_fn(parallel_tasks: usize, iterations: usize) {
96-
let task_fun = |_task_index: usize, _iteration: usize| -> ZResult<()> {
99+
let task_fun = |_task_index: usize, _iteration: usize| -> Result<(), ZAllocError> {
97100
let allocated_metadata = GLOBAL_METADATA_STORAGE.read().allocate()?;
98101
let descr = MetadataDescriptor::from(allocated_metadata.deref());
99102
let linked_metadata = GLOBAL_METADATA_SUBSCRIPTION.read().link(&descr)?;
@@ -136,8 +139,9 @@ fn metadata_check_memory_concurrent() {
136139
const VALIDATION_PERIOD: Duration = Duration::from_millis(100);
137140
const CONFIRMATION_PERIOD: Duration = Duration::from_millis(50);
138141

139-
fn watchdog_confirmed_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static {
140-
|_task_index: usize, _iteration: usize| -> ZResult<()> {
142+
fn watchdog_confirmed_fn(
143+
) -> impl Fn(usize, usize) -> Result<(), ZAllocError> + Clone + Send + Sync + 'static {
144+
|_task_index: usize, _iteration: usize| {
141145
let allocated = GLOBAL_METADATA_STORAGE.read().allocate()?;
142146
let confirmed = GLOBAL_CONFIRMATOR.read().add(allocated.clone());
143147

@@ -146,7 +150,8 @@ fn watchdog_confirmed_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Sen
146150
std::thread::sleep(VALIDATION_PERIOD);
147151
let valid = confirmed.owned.test_validate() != 0;
148152
if !valid {
149-
bail!("Invalid watchdog, iteration {i}");
153+
error!("Invalid watchdog, iteration {i}");
154+
return Err(ZAllocError::Other);
150155
}
151156
}
152157
Ok(())
@@ -185,8 +190,9 @@ fn watchdog_confirmed_dangling() {
185190
}
186191
}
187192

188-
fn watchdog_validated_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Send + Sync + 'static {
189-
|_task_index: usize, _iteration: usize| -> ZResult<()> {
193+
fn watchdog_validated_fn(
194+
) -> impl Fn(usize, usize) -> Result<(), ZAllocError> + Clone + Send + Sync + 'static {
195+
|_task_index: usize, _iteration: usize| {
190196
let allocated = GLOBAL_METADATA_STORAGE.read().allocate()?;
191197
let confirmed = GLOBAL_CONFIRMATOR.read().add(allocated.clone());
192198

@@ -200,7 +206,8 @@ fn watchdog_validated_fn() -> impl Fn(usize, usize) -> ZResult<()> + Clone + Sen
200206
.watchdog_invalidated
201207
.load(std::sync::atomic::Ordering::SeqCst)
202208
{
203-
bail!("Invalid watchdog, iteration {i}");
209+
error!("Invalid watchdog, iteration {i}");
210+
return Err(ZAllocError::Other);
204211
}
205212
}
206213

0 commit comments

Comments
 (0)