Implement remaining tests for server::handler, fix process cleanup in server state when terminates, fix symlink evaluation for metadata

pull/38/head
Chip Senkbeil 3 years ago
parent 7da28fecab
commit 22829d9cc8
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

File diff suppressed because it is too large Load Diff

@ -10,18 +10,18 @@ use tokio::{
task::{JoinError, JoinHandle},
};
/// Holds state related to multiple clients managed by a server
/// Holds state related to multiple connections managed by a server
#[derive(Default)]
pub struct State {
/// Map of all processes running on the server
pub processes: HashMap<usize, Process>,
/// List of processes that will be killed when a client drops
/// List of processes that will be killed when a connection drops
client_processes: HashMap<usize, Vec<usize>>,
}
impl State {
/// Pushes a new process associated with a client
/// Pushes a new process associated with a connection
pub fn push_process(&mut self, conn_id: usize, process: Process) {
self.client_processes
.entry(conn_id)
@ -30,6 +30,16 @@ impl State {
self.processes.insert(process.id, process);
}
/// Removes a process associated with a connection
pub fn remove_process(&mut self, conn_id: usize, proc_id: usize) {
self.client_processes.entry(conn_id).and_modify(|v| {
if let Some(pos) = v.iter().position(|x| *x == proc_id) {
v.remove(pos);
}
});
self.processes.remove(&proc_id);
}
/// Closes stdin for all processes associated with the connection
pub fn close_stdin_for_connection(&mut self, conn_id: usize) {
debug!("<Conn @ {:?}> Closing stdin to all processes", conn_id);

@ -135,7 +135,7 @@ impl ConnTracker {
}
#[cfg(test)]
mod tsets {
mod tests {
use super::*;
use std::thread;

@ -0,0 +1,3 @@
#!/usr/bin/env bash
sleep "$1"

@ -12,8 +12,8 @@ use rstest::*;
use std::path::PathBuf;
lazy_static::lazy_static! {
static ref SCRIPT_DIR: PathBuf =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("scripts").join("test");
static ref ROOT_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
static ref SCRIPT_DIR: PathBuf = ROOT_DIR.join("scripts").join("test");
static ref ECHO_ARGS_TO_STDOUT_SH: PathBuf = SCRIPT_DIR.join("echo_args_to_stdout.sh");
static ref ECHO_ARGS_TO_STDERR_SH: PathBuf = SCRIPT_DIR.join("echo_args_to_stderr.sh");

Loading…
Cancel
Save