Skip to content

Commit c276a8e

Browse files
committed
test refactor
1 parent c883151 commit c276a8e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

libwasmvm/src/cache.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ pub extern "C" fn release_cache(cache: *mut cache_t) {
328328

329329
#[cfg(test)]
330330
mod tests {
331+
use crate::assert_approx_eq;
332+
331333
use super::*;
332334
use std::iter::FromIterator;
333335
use tempfile::TempDir;
@@ -711,13 +713,10 @@ mod tests {
711713
assert_eq!(misses, 0);
712714
assert_eq!(elements_pinned_memory_cache, 1);
713715
assert_eq!(elements_memory_cache, 0);
714-
let expected = 5602873; // +/- 20%
715-
assert!(
716-
size_pinned_memory_cache > expected * 80 / 100,
717-
"size_pinned_memory_cache: {size_pinned_memory_cache}"
718-
);
719-
assert!(
720-
size_pinned_memory_cache < expected * 120 / 100,
716+
assert_approx_eq!(
717+
size_pinned_memory_cache,
718+
5602873,
719+
"0.2",
721720
"size_pinned_memory_cache: {size_pinned_memory_cache}"
722721
);
723722
assert_eq!(size_memory_cache, 0);

libwasmvm/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ macro_rules! assert_approx_eq {
2424
}
2525

2626
#[track_caller]
27-
fn assert_approx_eq_impl<U: Into<Uint128>>(
27+
pub fn assert_approx_eq_impl<U: Into<Uint128>>(
2828
left: U,
2929
right: U,
3030
max_rel_diff: &str,

0 commit comments

Comments
 (0)