Skip to content

Commit 64e985d

Browse files
committed
Finish timeout implementation
This adds a test, sets the default timeout to 120s and fixes the implementation to actually exit the process. Signed-off-by: Tim Buchwaldt <[email protected]>
1 parent 3631086 commit 64e985d

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
sleep 10

core-dump-composer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl CoreConfig {
5959
let pathname = matches.value_of("pathname").unwrap_or("").to_string();
6060
let timeout = matches
6161
.value_of("timeout")
62-
.unwrap_or("60")
62+
.unwrap_or("120")
6363
.parse::<u64>()
6464
.unwrap();
6565

core-dump-composer/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod logging;
2121
fn main() -> Result<(), anyhow::Error> {
2222
let (send, recv) = channel();
2323
let cc = config::CoreConfig::new()?;
24-
let timeout = cc.params.timeout.clone();
24+
let timeout = cc.params.timeout;
2525

2626
thread::spawn(move || {
2727
let result = handle(cc);
@@ -32,7 +32,10 @@ fn main() -> Result<(), anyhow::Error> {
3232

3333
match result {
3434
Ok(inner_result) => inner_result,
35-
Err(error) => panic!("Timeout: {}", error),
35+
Err(_error) => {
36+
println!("timeout");
37+
process::exit(1);
38+
}
3639
}
3740
}
3841

core-dump-composer/tests/timeout.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use std::env;
2+
use std::process::{Command, Stdio};
3+
4+
#[test]
5+
fn timeout_scenario() -> Result<(), std::io::Error> {
6+
let current_dir = env::current_dir()?;
7+
8+
println!("The current directory is {}", current_dir.display());
9+
// Need to append to path
10+
let key = "PATH";
11+
let mut current_path = String::new();
12+
match env::var(key) {
13+
Ok(val) => current_path = val,
14+
Err(e) => println!("couldn't interpret {}: {}", key, e),
15+
}
16+
let new_path = format!(
17+
"{}/mocks:{}/target/debug:{}",
18+
current_dir.display(),
19+
current_dir.display(),
20+
current_path
21+
);
22+
println!("Running tests using this PATH: {}", new_path);
23+
let output_folder = format!("{}/{}", ".", "output");
24+
// Make a directory to store the generated zip file
25+
let _mkdir = match Command::new("mkdir").arg("-p").arg(&output_folder).spawn() {
26+
Err(why) => panic!("couldn't spawn mkdir: {}", why),
27+
Ok(process) => process,
28+
};
29+
// copy crictl to base_folder
30+
Command::new("cp")
31+
.arg("-f")
32+
.arg("./mocks/crictl-timeout.sh")
33+
.arg("../target/debug/crictl")
34+
.output()
35+
.expect("cp failed");
36+
37+
// cat the test core file to process.
38+
let cat = Command::new("cat")
39+
.env("PATH", &new_path)
40+
.arg("./mocks/test.core")
41+
.stdout(Stdio::piped())
42+
.spawn()?
43+
.stdout
44+
.unwrap();
45+
46+
let cdc = Command::new("../target/debug/core-dump-composer")
47+
.arg("-c")
48+
.arg("1000000000")
49+
.arg("-e")
50+
.arg("node")
51+
.arg("-p")
52+
.arg("4")
53+
.arg("-s")
54+
.arg("10")
55+
.arg("-E")
56+
.arg("!target!debug!core-dump-composer")
57+
.arg("-d")
58+
.arg(&output_folder)
59+
.arg("-t")
60+
.arg("1588462466")
61+
.arg("-h")
62+
.arg("crashing-app-699c49b4ff-86wrh")
63+
.arg("--timeout")
64+
.arg("1")
65+
.stdin(cat)
66+
.output()
67+
.expect("Couldn't execute");
68+
69+
println!("{}", String::from_utf8_lossy(&cdc.stdout));
70+
assert_eq!("timeout\n", String::from_utf8_lossy(&cdc.stdout));
71+
assert_eq!(1, *&cdc.status.code().unwrap());
72+
Ok(())
73+
}

0 commit comments

Comments
 (0)