in src/enclave_proc/socket.rs [292:335]
fn test_close() {
let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID);
assert!(socket.is_ok());
// Get number of running threads before spawning the socket removal listener thread
let out_cmd0 = Command::new("cat")
.arg(format!("/proc/{}/status", std::process::id()))
.output()
.expect("Failed to run cat");
let out0 = std::str::from_utf8(&out_cmd0.stdout).unwrap();
let crt_num_threads0 = get_num_threads_from_status_output(out0.to_string());
if let Ok(mut socket) = socket {
let _ = UnixListener::bind(socket.get_path())
.map_err(|e| {
new_nitro_cli_failure!(
&format!("Failed to bind to socket: {:?}", e),
NitroCliErrorEnum::SocketError
)
})
.ok_or_exit_with_errno(Some("Error binding"));
let result = socket.start_monitoring(true);
assert!(result.is_ok());
// Call `close_mut()` and expect `socket.requested_remove` to change to True
let result = socket.close_mut();
assert!(result.is_ok());
assert!(socket.requested_remove.load(Ordering::SeqCst));
}
// Get number of running threads after closing the socket removal listener thread
let out_cmd1 = Command::new("cat")
.arg(format!("/proc/{}/status", std::process::id()))
.output()
.expect("Failed to run cat");
let out1 = std::str::from_utf8(&out_cmd1.stdout).unwrap();
let crt_num_threads1 = get_num_threads_from_status_output(out1.to_string());
// Check that the number of threads remains the same before and after running the test
assert_eq!(crt_num_threads0, crt_num_threads1);
}