test(linux): exercise production self-test stream reader
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
Some checks failed
Desktop Release / Bootstrap updater signing key (push) Has been cancelled
Desktop Release / Windows x64 NSIS (push) Has been cancelled
Desktop Release / Linux x64 DEB + AppImage (push) Has been cancelled
Desktop Release / Publish public desktop release (push) Has been cancelled
This commit is contained in:
parent
5b5bda8e6b
commit
09d817f748
@ -156,32 +156,28 @@ fn test_capture_sink_loop(
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn handle_test_capture_stream(mut stream: TcpStream, state: SharedState, app: AppHandle) {
|
||||
let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
|
||||
fn read_test_capture_stream<R: Read>(mut reader: R) -> std::io::Result<Vec<u8>> {
|
||||
let mut bytes = Vec::new();
|
||||
let mut buffer = [0u8; 32 * 1024];
|
||||
|
||||
loop {
|
||||
match stream.read(&mut buffer) {
|
||||
match reader.read(&mut buffer) {
|
||||
Ok(0) => break,
|
||||
Ok(read) => bytes.extend_from_slice(&buffer[..read]),
|
||||
Err(error) if matches!(error.kind(), ErrorKind::WouldBlock | ErrorKind::TimedOut) => break,
|
||||
Err(error) => {
|
||||
process_payload(
|
||||
&state,
|
||||
&app,
|
||||
"cups-test",
|
||||
"FieldLens-Test-Capture".into(),
|
||||
bytes,
|
||||
false,
|
||||
Some(format!("test capture read failed: {error}")),
|
||||
);
|
||||
return;
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
if !bytes.is_empty() {
|
||||
process_payload(
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn handle_test_capture_stream(mut stream: TcpStream, state: SharedState, app: AppHandle) {
|
||||
let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
|
||||
|
||||
match read_test_capture_stream(&mut stream) {
|
||||
Ok(bytes) if !bytes.is_empty() => process_payload(
|
||||
&state,
|
||||
&app,
|
||||
"cups-test",
|
||||
@ -189,7 +185,17 @@ fn handle_test_capture_stream(mut stream: TcpStream, state: SharedState, app: Ap
|
||||
bytes,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
),
|
||||
Ok(_) => {}
|
||||
Err(error) => process_payload(
|
||||
&state,
|
||||
&app,
|
||||
"cups-test",
|
||||
"FieldLens-Test-Capture".into(),
|
||||
vec![],
|
||||
false,
|
||||
Some(format!("test capture read failed: {error}")),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -910,30 +916,17 @@ mod self_test_regressions {
|
||||
use super::*;
|
||||
use std::io::Cursor;
|
||||
|
||||
fn read_test_capture<R: Read>(mut reader: R) -> Result<Vec<u8>, std::io::Error> {
|
||||
let mut bytes = Vec::new();
|
||||
let mut buffer = [0u8; 32 * 1024];
|
||||
loop {
|
||||
match reader.read(&mut buffer) {
|
||||
Ok(0) => break,
|
||||
Ok(read) => bytes.extend_from_slice(&buffer[..read]),
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
}
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn self_test_stream_payload_is_preserved_for_capture_processing() {
|
||||
let payload = b"%PDF-1.4\nFieldLens capture self-test\n%%EOF\n";
|
||||
let bytes = read_test_capture(Cursor::new(payload)).expect("read self-test payload");
|
||||
let bytes = read_test_capture_stream(Cursor::new(payload)).expect("read self-test payload");
|
||||
assert_eq!(bytes, payload);
|
||||
assert!(!bytes.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_self_test_stream_stays_empty() {
|
||||
let bytes = read_test_capture(Cursor::new(Vec::<u8>::new()))
|
||||
let bytes = read_test_capture_stream(Cursor::new(Vec::<u8>::new()))
|
||||
.expect("read empty self-test payload");
|
||||
assert!(bytes.is_empty());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user