48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
use super::*;
|
|
use std::{
|
|
process::Command,
|
|
time::{Duration, Instant},
|
|
};
|
|
|
|
#[test]
|
|
fn native_http_open_stream_upload_early_close_and_cancel() {
|
|
let directory = Directory::new();
|
|
let project = Project::load(&fixture().with_file_name("http-stream.dever")).unwrap();
|
|
let program = project.check().unwrap();
|
|
let binary = build::build(
|
|
&program,
|
|
&project.sources,
|
|
"verify",
|
|
&directory.0.join("http-stream"),
|
|
)
|
|
.unwrap();
|
|
let output_path = directory.0.join("stdout");
|
|
let error_path = directory.0.join("stderr");
|
|
let mut child = Command::new(binary)
|
|
.stdout(std::fs::File::create(&output_path).unwrap())
|
|
.stderr(std::fs::File::create(&error_path).unwrap())
|
|
.spawn()
|
|
.unwrap();
|
|
let start = Instant::now();
|
|
let status = loop {
|
|
if let Some(status) = child.try_wait().unwrap() {
|
|
break status;
|
|
}
|
|
if start.elapsed() > Duration::from_secs(20) {
|
|
child.kill().unwrap();
|
|
child.wait().unwrap();
|
|
panic!(
|
|
"streaming native test timed out: {}",
|
|
std::fs::read_to_string(&error_path).unwrap()
|
|
);
|
|
}
|
|
std::thread::sleep(Duration::from_millis(10));
|
|
};
|
|
assert!(
|
|
status.success(),
|
|
"{}",
|
|
std::fs::read_to_string(&error_path).unwrap()
|
|
);
|
|
assert_eq!(std::fs::read(output_path).unwrap(), b"true\n");
|
|
}
|