Skip to content

Commit ddf5189

Browse files
committed
Fix unit test.
1 parent 302ff04 commit ddf5189

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

memapi/src/memorytracking.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,10 @@ fn write_flamegraph<'a, I: IntoIterator<Item = &'a str>>(
295295

296296
#[cfg(test)]
297297
mod tests {
298-
use super::{AllocationTracker, Callstack};
298+
use super::{AllocationTracker, CallSite, Callstack};
299299
use itertools::Itertools;
300300
use proptest::prelude::*;
301+
use smallstr::SmallString;
301302
use std::collections;
302303

303304
proptest! {
@@ -356,19 +357,31 @@ mod tests {
356357
#[test]
357358
fn combine_callstacks_and_sum_allocations() {
358359
let mut tracker = AllocationTracker::new();
360+
let id1 = tracker.call_sites.get_or_insert_id(CallSite {
361+
module_name: SmallString::from_str("a"),
362+
function_name: SmallString::from_str("af"),
363+
});
364+
let id2 = tracker.call_sites.get_or_insert_id(CallSite {
365+
module_name: SmallString::from_str("b"),
366+
function_name: SmallString::from_str("bf"),
367+
});
368+
let id3 = tracker.call_sites.get_or_insert_id(CallSite {
369+
module_name: SmallString::from_str("c"),
370+
function_name: SmallString::from_str("cf"),
371+
});
359372
let mut cs1 = Callstack::new();
360-
cs1.start_call(1);
361-
cs1.start_call(2);
373+
cs1.start_call(id1);
374+
cs1.start_call(id2);
362375
let mut cs2 = Callstack::new();
363-
cs2.start_call(3);
376+
cs2.start_call(id3);
364377

365378
tracker.add_allocation(1, 1000, cs1.clone());
366379
tracker.add_allocation(2, 234, cs2.clone());
367380
tracker.add_allocation(3, 50000, cs1.clone());
368381

369382
let mut expected: collections::HashMap<String, usize> = collections::HashMap::new();
370-
expected.insert("a;b".to_string(), 51000);
371-
expected.insert("c".to_string(), 234);
383+
expected.insert("a:af;b:bf".to_string(), 51000);
384+
expected.insert("c:cf".to_string(), 234);
372385
assert_eq!(expected, tracker.combine_callstacks());
373386
}
374387
}

0 commit comments

Comments
 (0)