diff --git a/tests/simulation/command_execution.rs b/tests/simulation/command_execution.rs index ca91c81..a441dfc 100644 --- a/tests/simulation/command_execution.rs +++ b/tests/simulation/command_execution.rs @@ -2,8 +2,7 @@ use crate::simulation::*; #[test] fn simulate_archive_is_stored_correctly() -> Result<(), std::io::Error> { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("archive_is_stored_correctly"); - let _sched = start_scheduler("archive_is_stored_correctly")?; + let (_sched, mut com, _socat) = start_scheduler("archive_is_stored_correctly").unwrap(); simulate_test_store_archive(&mut com, 1).unwrap(); std::thread::sleep(std::time::Duration::from_millis(400)); @@ -27,8 +26,7 @@ fn simulate_archive_is_stored_correctly() -> Result<(), std::io::Error> { #[test] fn return_result_is_retried_n_times() { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("return_result_retries"); - let _sched = start_scheduler("return_result_retries").unwrap(); + let (_sched, mut com, _socat) = start_scheduler("return_result_retries").unwrap(); simulate_test_store_archive(&mut com, 8).unwrap(); simulate_execute_program(&mut com, 8, 0, 5).unwrap(); @@ -41,3 +39,21 @@ fn return_result_is_retried_n_times() { } assert_eq!([0u8], *simulate_get_status(&mut com).unwrap()); } + +#[test] +fn result_is_deleted_after_transfer() { + let (_sched, mut com, _socat) = start_scheduler("results_deleted").unwrap(); + + simulate_test_store_archive(&mut com, 8).unwrap(); + simulate_execute_program(&mut com, 8, 3, 5).unwrap(); + std::thread::sleep(std::time::Duration::from_millis(400)); + assert_eq!(simulate_get_status(&mut com).unwrap(), get_status_program_finished(8, 3, 0)); + assert_eq!(simulate_get_status(&mut com).unwrap(), get_status_result_ready(8, 3)); + + simulate_return_result(&mut com, 8, 3).unwrap(); + com.send_packet(&CEPPacket::Ack).unwrap(); + + assert_eq!(simulate_get_status(&mut com).unwrap(), vec![0]); + assert_eq!(std::fs::read_dir("tests/tmp/results_deleted/data").unwrap().count(), 0); + assert_eq!(std::fs::read_dir("tests/tmp/results_deleted/archives/8/results").unwrap().count(), 0); +} diff --git a/tests/simulation/full_run.rs b/tests/simulation/full_run.rs index e357112..f52b5c6 100644 --- a/tests/simulation/full_run.rs +++ b/tests/simulation/full_run.rs @@ -3,8 +3,7 @@ use std::{io::Cursor, time::Duration}; #[test] fn full_run() { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("full_run"); - let _sched = start_scheduler("full_run").unwrap(); + let (_sched, mut com, _socat) = start_scheduler("full_run").unwrap(); // store and execute program simulate_test_store_archive(&mut com, 1).unwrap(); diff --git a/tests/simulation/logging.rs b/tests/simulation/logging.rs index 01e1b67..e3503d1 100644 --- a/tests/simulation/logging.rs +++ b/tests/simulation/logging.rs @@ -2,8 +2,8 @@ use crate::simulation::*; #[test] fn logfile_is_created() -> Result<(), std::io::Error> { - let (_, _proc) = SimulationComHandle::with_socat_proc("log_created"); - let _sched = start_scheduler("log_created")?; + let (_sched, _com, _socat) = start_scheduler("log_created").unwrap(); + std::thread::sleep(std::time::Duration::from_millis(400)); assert!(std::path::Path::new("./tests/tmp/log_created/log").exists()); @@ -12,8 +12,7 @@ fn logfile_is_created() -> Result<(), std::io::Error> { #[test] fn logfile_is_cleared_after_sent() -> std::io::Result<()> { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("log_is_cleared_after_sent"); - let _sched = start_scheduler("log_is_cleared_after_sent")?; + let (_sched, mut com, _socat) = start_scheduler("log_is_cleared_after_sent").unwrap(); simulate_test_store_archive(&mut com, 1).unwrap(); com.send_packet(&CEPPacket::Data(execute_program(1, 0, 3))).unwrap(); diff --git a/tests/simulation/mod.rs b/tests/simulation/mod.rs index 02586e5..315faa0 100644 --- a/tests/simulation/mod.rs +++ b/tests/simulation/mod.rs @@ -17,17 +17,17 @@ pub struct SimulationComHandle { } impl SimulationComHandle { - fn with_socat_proc(unique: &str) -> (Self, PoisonedChild) { + fn with_socat_proc(socket_path: &str) -> (Self, PoisonedChild) { let mut proc = std::process::Command::new("socat") .arg("stdio") - .arg(format!("pty,raw,echo=0,link=/tmp/ttySTS1-{},b921600,wait-slave", unique)) + .arg(format!("pty,raw,echo=0,link={},b921600,wait-slave", socket_path)) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() .unwrap(); loop { - if std::path::Path::new(&format!("/tmp/ttySTS1-{unique}")).exists() { + if std::path::Path::new(socket_path).exists() { break; } std::thread::sleep(Duration::from_millis(50)); @@ -66,7 +66,7 @@ impl CommunicationHandle for SimulationComHandle { fn get_config_str(unique: &str) -> String { format!( " - uart = \"/tmp/ttySTS1-{unique}\" + uart = \"uart\" baudrate = 921600 heartbeat_pin = 34 update_pin = 35 @@ -85,17 +85,18 @@ impl Drop for PoisonedChild { } } -fn start_scheduler(unique: &str) -> Result { +fn start_scheduler(unique: &str) -> Result<(PoisonedChild, SimulationComHandle, PoisonedChild), std::io::Error> { let test_dir = format!("./tests/tmp/{}", unique); let scheduler_bin = std::fs::canonicalize("./target/release/STS1_EDU_Scheduler")?; let _ = std::fs::remove_dir_all(&test_dir); std::fs::create_dir_all(&test_dir)?; std::fs::write(format!("{}/config.toml", &test_dir), get_config_str(unique))?; + let (handle, socat) = SimulationComHandle::with_socat_proc(&format!("{}/uart", test_dir)); let scheduler = std::process::Command::new(scheduler_bin).current_dir(test_dir).spawn().unwrap(); - Ok(PoisonedChild(scheduler)) + Ok((PoisonedChild(scheduler), handle, socat)) } pub fn simulate_test_store_archive( diff --git a/tests/simulation/socket.rs b/tests/simulation/socket.rs index df17615..71dd8d8 100644 --- a/tests/simulation/socket.rs +++ b/tests/simulation/socket.rs @@ -2,12 +2,12 @@ use std::io::Write; use std::os::unix::net::UnixStream; use std::time::Duration; -use super::{simulate_get_status, start_scheduler, SimulationComHandle}; +use super::{simulate_get_status, start_scheduler}; #[test] fn dosimeter_events_are_added() { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("dosimeter"); - let _sched = start_scheduler("dosimeter").unwrap(); + let (_sched, mut com, _socat) = start_scheduler("dosimeter").unwrap(); + std::thread::sleep(Duration::from_millis(200)); { @@ -21,11 +21,11 @@ fn dosimeter_events_are_added() { #[test] fn multiple_dosimeter_events() { - let (mut com, _socat) = SimulationComHandle::with_socat_proc("dosimeter-multi"); - let _sched = start_scheduler("dosimeter-multi").unwrap(); + let (_sched, mut com, _socat) = start_scheduler("dosimeter_multi").unwrap(); + std::thread::sleep(Duration::from_millis(200)); - let mut socket = UnixStream::connect("/tmp/STS1_EDU_Scheduler_SIM_dosimeter-multi").unwrap(); + let mut socket = UnixStream::connect("/tmp/STS1_EDU_Scheduler_SIM_dosimeter_multi").unwrap(); for _ in 0..10 { writeln!(socket, "dosimeter/on").unwrap(); writeln!(socket, "dosimeter/off").unwrap(); diff --git a/tests/simulation/timeout.rs b/tests/simulation/timeout.rs index 632962f..98c1910 100644 --- a/tests/simulation/timeout.rs +++ b/tests/simulation/timeout.rs @@ -1,11 +1,10 @@ -use super::{get_status, start_scheduler, SimulationComHandle}; +use super::{get_status, start_scheduler}; use std::time::Duration; use STS1_EDU_Scheduler::communication::{CEPPacket, CommunicationHandle}; #[test] fn integrity_ack_timeout_is_honored() { - let (mut cobc, _socat) = SimulationComHandle::with_socat_proc("integrity_timeout"); - let _sched = start_scheduler("integrity_timeout").unwrap(); + let (_sched, mut cobc, _socat) = start_scheduler("integrity_timeout").unwrap(); // Check that delayed ACK is allowed cobc.send_packet(&CEPPacket::Data(get_status())).unwrap();