Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular Buffer: added memory leak tests for overwrite and read #1652

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions exercises/practice/circular-buffer/tests/circular-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ fn clear_actually_frees_up_its_elements() {
assert_eq!(Rc::strong_count(&element), 1);
}

#[test]
#[ignore]
fn overwrite_frees_up_the_cleared_elements() {
let mut buffer = CircularBuffer::new(1);
let element_to_replace = Rc::new(());
let new_element = Rc::new(());
assert!(buffer.write(Rc::clone(&element_to_replace)).is_ok());
assert_eq!(Rc::strong_count(&element_to_replace), 2);
buffer.overwrite(Rc::clone(&new_element));
assert_eq!(Rc::strong_count(&element_to_replace), 1);
}

#[test]
#[ignore]
fn read_frees_up_the_read_element() {
let mut buffer = CircularBuffer::new(1);
let element = Rc::new(());
assert!(buffer.write(Rc::clone(&element)).is_ok());
assert_eq!(Rc::strong_count(&element), 2);
assert!(buffer.read().is_ok());
assert_eq!(Rc::strong_count(&element), 1);
}

#[test]
#[ignore]
fn overwrite_acts_like_write_on_non_full_buffer() {
Expand Down
Loading