Skip to content

Commit

Permalink
Update interceptors test
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 24, 2024
1 parent 2b16da8 commit f210356
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions zenoh/tests/interceptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ fn downsampling() {
// declare subscriber
let zenoh_sub = zenoh::open(config).res().unwrap();

let count_r100 = Arc::new(Mutex::new(0));
let count_r100 = Arc::new(Mutex::new(0 as i64));
let count_r100_clone = count_r100.clone();

let count_r50 = Arc::new(Mutex::new(0));
let count_r50 = Arc::new(Mutex::new(0 as i64));
let count_r50_clone = count_r50.clone();

let _sub = zenoh_sub
Expand Down Expand Up @@ -60,24 +60,21 @@ fn downsampling() {
.res()
.unwrap();

let interval = std::time::Duration::from_millis(10);
let interval = std::time::Duration::from_millis(1);
let start_time = std::time::Instant::now();
for i in 0..100 {
for i in 0..1000 {
println!("message {}", i);
publisher_r100.put(format!("message {}", i)).res().unwrap();
publisher_r50.put(format!("message {}", i)).res().unwrap();

std::thread::sleep(interval);
}

// check result count of queries
// check result count of queries (with an error of 10%)
let full_elapsed_time = std::time::Instant::now() - start_time;
assert_eq!(
*count_r100.lock().unwrap(),
full_elapsed_time.as_millis() / 100
);
assert_eq!(
*count_r50.lock().unwrap(),
full_elapsed_time.as_millis() / 50
);
let expected_count_r100 = (full_elapsed_time.as_millis() / 100) as i64;
assert!((*count_r100.lock().unwrap() - expected_count_r100).abs() <= expected_count_r100 / 10);

let expected_count_r50 = (full_elapsed_time.as_millis() / 50) as i64;
assert!((*count_r50.lock().unwrap() - expected_count_r50).abs() <= expected_count_r50 / 10);
}

0 comments on commit f210356

Please sign in to comment.