Skip to content

Commit

Permalink
test: ensure packets in read_buffer aren't forgotten
Browse files Browse the repository at this point in the history
  • Loading branch information
de-sh committed Oct 13, 2024
1 parent ab2ce8d commit 678a616
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,35 @@ mod test {
let files = get_file_ids(&backup.path(), 10).unwrap();
assert_eq!(files, vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19]);
}

#[test]
fn ensure_current_read_file_is_not_lost() {
let backup = init_backup_folders();
let mut storage = Storage::new("test", 10 * 1036);
storage.set_persistence(backup.path(), 10).unwrap();
// partially fill write buffer
write_n_publishes(&mut storage, 1);

// Nothing written to disk
assert!(storage.persistence.as_ref().unwrap().backlog_files.is_empty());

// Trigger swap of read and write buffers, ensure packets in read buffer
storage.reload_on_eof().unwrap();
assert!(!storage.current_read_file.is_empty());
assert!(storage.persistence.as_ref().unwrap().current_read_file_id.is_none());

// Trigger flush onto disk, and drop storage
storage.flush().unwrap();
drop(storage);

// reload storage
let mut storage = Storage::new("test", 10 * 1036);
storage.set_persistence(backup.path(), 10).unwrap();

// verify read buffer was persisted by reading a single packet
read_n_publishes(&mut storage, 1);
assert_eq!(storage.file_count(), 1);
let file_id = storage.persistence.as_ref().unwrap().current_read_file_id.unwrap();
assert_eq!(file_id, 0);
}
}

0 comments on commit 678a616

Please sign in to comment.