fix(pdftract-1psmn): fix mmap test compilation errors

- Add std::sync::Arc import for thread sharing
- Fix lifetime issue in test_sync_multiple_threads using Arc
- Add mut to source in test_empty_file for Read trait

All FileSource tests pass (12/12).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-28 02:19:44 -04:00
parent a2da014936
commit 823712d65c
2 changed files with 11 additions and 5 deletions

View file

@ -177,6 +177,7 @@ mod tests {
use super::*; use super::*;
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::sync::Arc;
use std::thread; use std::thread;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
@ -335,14 +336,14 @@ mod tests {
let content = b"0123456789"; let content = b"0123456789";
temp_file.write_all(content).unwrap(); temp_file.write_all(content).unwrap();
let source = MmapSource::open(temp_file.path()).unwrap(); let source = Arc::new(MmapSource::open(temp_file.path()).unwrap());
// Spawn multiple threads reading concurrently // Spawn multiple threads reading concurrently
let handles: Vec<_> = (0..4) let handles: Vec<_> = (0..4)
.map(|i| { .map(|i| {
let source_ref = &source; let source_clone = Arc::clone(&source);
thread::spawn(move || { thread::spawn(move || {
let bytes = source_ref.read_range(i as u64, 2).unwrap(); let bytes = source_clone.read_range(i as u64, 2).unwrap();
bytes.to_vec() bytes.to_vec()
}) })
}) })
@ -434,7 +435,7 @@ mod tests {
#[test] #[test]
fn test_empty_file() { fn test_empty_file() {
let temp_file = NamedTempFile::new().unwrap(); let temp_file = NamedTempFile::new().unwrap();
let source = MmapSource::open(temp_file.path()).unwrap(); let mut source = MmapSource::open(temp_file.path()).unwrap();
assert_eq!(source.len(), 0); assert_eq!(source.len(), 0);
let mut buf = [0u8; 10]; let mut buf = [0u8; 10];

View file

@ -25,7 +25,12 @@ Implemented FileSource as a PdfSource fallback for when memory-mapping is not av
- `test_large_file`: Handles 100KB file - `test_large_file`: Handles 100KB file
- `test_read_mixed_with_seek`: Tests mixed read/seek operations - `test_read_mixed_with_seek`: Tests mixed read/seek operations
### 2. crates/pdftract-core/Cargo.toml ### 2. crates/pdftract-core/src/source/mmap.rs (test fixes)
- Added `std::sync::Arc` import for thread sharing
- Fixed lifetime issue in `test_sync_multiple_threads` by using Arc instead of `&source`
- Added `mut` to source in `test_empty_file` for Read trait compatibility
### 3. crates/pdftract-core/Cargo.toml
- Added `parking_lot = "0.12"` dependency - Added `parking_lot = "0.12"` dependency
## Acceptance Criteria ## Acceptance Criteria