#![allow(missing_docs)]
use std::fs::File;
use std::io::Write;
use std::time::Duration;
use tempfile::NamedTempFile;
use wireshift_core::backend::{Backend, BackendSubmission};
use wireshift_core::buffer::Buffer;
use wireshift_core::config::RingConfig;
use wireshift_core::op::{CompletionPayload, OpDescriptor};
use wireshift_uring::UringBackend;
#[test]
fn test_property_read_bytes() {
let mut temp_file = NamedTempFile::new().unwrap();
let file_content = vec![0xAB; 100];
temp_file.write_all(&file_content).unwrap();
let file = temp_file.reopen().unwrap();
let config = RingConfig::default();
let (tx, rx) = std::sync::mpsc::channel();
let backend = UringBackend::new(&config, tx).unwrap();
let buffer = Buffer::from_vec(vec![0u8; 200]).unwrap();
let submission = BackendSubmission { timeout: None,
id: 42,
descriptor: OpDescriptor::Read {
file,
offset: 0,
buffer,
len: None,
},
};
backend.submit(submission).unwrap();
let completion = rx
.recv_timeout(Duration::from_secs(5))
.expect("read timed out");
assert_eq!(completion.id, 42);
if let CompletionPayload::Read { bytes, .. } = completion.result.unwrap() {
assert_eq!(bytes, 100, "returned bytes should equal min(N, M)");
} else {
panic!("unexpected payload type");
}
}