mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-02 06:08:42 +00:00
feat: forbid reusing existing Runner
This commit is contained in:
parent
9880b8e4e7
commit
466eb70078
1 changed files with 23 additions and 12 deletions
|
@ -32,6 +32,9 @@ impl Runner {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self) {
|
pub fn start(&mut self) {
|
||||||
|
match self.process {
|
||||||
|
Some(_) => panic!("Cannot reuse existing Runner"),
|
||||||
|
None => {
|
||||||
self.process = Some(
|
self.process = Some(
|
||||||
Command::new(&self.command)
|
Command::new(&self.command)
|
||||||
.args(&self.args)
|
.args(&self.args)
|
||||||
|
@ -42,6 +45,8 @@ impl Runner {
|
||||||
.expect("Failed to execute runner"),
|
.expect("Failed to execute runner"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn terminate(&mut self) {
|
pub fn terminate(&mut self) {
|
||||||
match self.process.as_mut() {
|
match self.process.as_mut() {
|
||||||
|
@ -51,7 +56,6 @@ impl Runner {
|
||||||
Some(proc) => {
|
Some(proc) => {
|
||||||
proc.kill().expect("Failed to kill process");
|
proc.kill().expect("Failed to kill process");
|
||||||
proc.wait().expect("Failed to wait for process");
|
proc.wait().expect("Failed to wait for process");
|
||||||
self.process = None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +113,11 @@ mod tests {
|
||||||
fn can_run_command_and_read_env() {
|
fn can_run_command_and_read_env() {
|
||||||
let mut env = HashMap::new();
|
let mut env = HashMap::new();
|
||||||
env.insert("REX2TEST".to_string(), "Lorem ipsum dolor".to_string());
|
env.insert("REX2TEST".to_string(), "Lorem ipsum dolor".to_string());
|
||||||
let mut runner = Runner::new(env, "bash".into(), vec!["-c".into(), "echo \"REX2TEST: $REX2TEST\"".into()]);
|
let mut runner = Runner::new(
|
||||||
|
env,
|
||||||
|
"bash".into(),
|
||||||
|
vec!["-c".into(), "echo \"REX2TEST: $REX2TEST\"".into()],
|
||||||
|
);
|
||||||
runner.start();
|
runner.start();
|
||||||
while runner.status() == RunnerStatus::Running {
|
while runner.status() == RunnerStatus::Running {
|
||||||
sleep(time::Duration::from_millis(10));
|
sleep(time::Duration::from_millis(10));
|
||||||
|
@ -117,6 +125,9 @@ mod tests {
|
||||||
runner.flush_out();
|
runner.flush_out();
|
||||||
assert_eq!(runner.status(), RunnerStatus::Stopped);
|
assert_eq!(runner.status(), RunnerStatus::Stopped);
|
||||||
assert_eq!(runner.stdout.len(), 2);
|
assert_eq!(runner.stdout.len(), 2);
|
||||||
assert_eq!(runner.stdout.get(0).unwrap(), "REX2TEST: Lorem ipsum dolor\n");
|
assert_eq!(
|
||||||
|
runner.stdout.get(0).unwrap(),
|
||||||
|
"REX2TEST: Lorem ipsum dolor\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue