Skip to content

Commit 645164b

Browse files
authored
test: add memory leak test (#726)
1 parent e03b08a commit 645164b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/tests/memory_leak.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::sync::Arc;
2+
3+
use crate::Resolver;
4+
5+
/// Test to prove memory leak in `CachedPath` Arc cycles
6+
#[test]
7+
fn test_memory_leak_arc_cycles() {
8+
let f = super::fixture_root().join("misc");
9+
10+
let resolver = Resolver::default();
11+
12+
let path = resolver.cache.value(&f);
13+
14+
resolver.resolve(&f, "package-json-nested").unwrap();
15+
16+
// Populated cache - path is now owned in multiple places.
17+
assert_eq!(Arc::strong_count(&path.0), 4);
18+
19+
// Drop the resolver.
20+
drop(resolver);
21+
22+
// All Arcs must be dropped, leaving the original count of 1.
23+
assert_eq!(Arc::strong_count(&path.0), 1);
24+
}

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod imports_field;
1111
mod incorrect_description_file;
1212
mod main_field;
1313
mod memory_fs;
14+
mod memory_leak;
1415
mod missing;
1516
mod module_type;
1617
mod package_json;

0 commit comments

Comments
 (0)