|
| 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