mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
parent
dab5457870
commit
dbf861f8a0
2 changed files with 46 additions and 49 deletions
|
@ -8,11 +8,13 @@ use std::path::PathBuf;
|
||||||
use std::process::Child;
|
use std::process::Child;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
use std::sync::atomic::AtomicUsize;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::MutexGuard;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref GUARD: Mutex<()> = Mutex::new(());
|
static ref SERVER: Mutex<Option<Child>> = Mutex::new(None);
|
||||||
|
static ref SERVER_COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn root_path() -> PathBuf {
|
pub fn root_path() -> PathBuf {
|
||||||
|
@ -35,45 +37,52 @@ pub fn deno_exe_path() -> PathBuf {
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HttpServerGuard<'a> {
|
pub struct HttpServerGuard {}
|
||||||
#[allow(dead_code)]
|
|
||||||
g: MutexGuard<'a, ()>,
|
|
||||||
child: Child,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for HttpServerGuard<'a> {
|
impl Drop for HttpServerGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
match self.child.try_wait() {
|
let count = SERVER_COUNT.fetch_sub(1, Ordering::Relaxed);
|
||||||
Ok(None) => {
|
// If no more tests hold guard we can kill the server
|
||||||
self.child.kill().expect("failed to kill http_server.py");
|
if count == 1 {
|
||||||
}
|
kill_http_server();
|
||||||
Ok(Some(status)) => {
|
|
||||||
panic!("http_server.py exited unexpectedly {}", status)
|
|
||||||
}
|
|
||||||
Err(e) => panic!("http_server.py err {}", e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts tools/http_server.py when the returned guard is dropped, the server
|
fn kill_http_server() {
|
||||||
/// will be killed.
|
let mut server_guard = SERVER.lock().unwrap();
|
||||||
pub fn http_server<'a>() -> HttpServerGuard<'a> {
|
let mut child = server_guard
|
||||||
// TODO(ry) Allow tests to use the http server in parallel.
|
.take()
|
||||||
let g = GUARD.lock().unwrap();
|
.expect("Trying to kill server but already killed");
|
||||||
|
match child.try_wait() {
|
||||||
println!("tools/http_server.py starting...");
|
Ok(None) => {
|
||||||
let mut child = Command::new("python")
|
child.kill().expect("failed to kill http_server.py");
|
||||||
.current_dir(root_path())
|
}
|
||||||
.args(&["-u", "tools/http_server.py"])
|
Ok(Some(status)) => panic!("http_server.py exited unexpectedly {}", status),
|
||||||
.stdout(Stdio::piped())
|
Err(e) => panic!("http_server.py err {}", e),
|
||||||
.spawn()
|
};
|
||||||
.expect("failed to execute child");
|
}
|
||||||
|
|
||||||
let stdout = child.stdout.as_mut().unwrap();
|
pub fn http_server() -> HttpServerGuard {
|
||||||
use std::io::{BufRead, BufReader};
|
SERVER_COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
let mut lines = BufReader::new(stdout).lines();
|
{
|
||||||
let line = lines.next().unwrap().unwrap();
|
let mut server_guard = SERVER.lock().unwrap();
|
||||||
assert!(line.starts_with("ready"));
|
if server_guard.is_none() {
|
||||||
|
println!("tools/http_server.py starting...");
|
||||||
HttpServerGuard { child, g }
|
let mut child = Command::new("python")
|
||||||
|
.current_dir(root_path())
|
||||||
|
.args(&["-u", "tools/http_server.py"])
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.expect("failed to execute child");
|
||||||
|
|
||||||
|
let stdout = child.stdout.as_mut().unwrap();
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
let mut lines = BufReader::new(stdout).lines();
|
||||||
|
let line = lines.next().unwrap().unwrap();
|
||||||
|
assert!(line.starts_with("ready"));
|
||||||
|
server_guard.replace(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HttpServerGuard {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,13 +156,11 @@ itest!(_018_async_catch {
|
||||||
output: "018_async_catch.ts.out",
|
output: "018_async_catch.ts.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(_019_media_types {
|
itest!(_019_media_types {
|
||||||
args: "run --reload 019_media_types.ts",
|
args: "run --reload 019_media_types.ts",
|
||||||
output: "019_media_types.ts.out",
|
output: "019_media_types.ts.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
itest!(_020_json_modules {
|
itest!(_020_json_modules {
|
||||||
args: "run --reload 020_json_modules.ts",
|
args: "run --reload 020_json_modules.ts",
|
||||||
|
@ -174,13 +172,11 @@ itest!(_021_mjs_modules {
|
||||||
output: "021_mjs_modules.ts.out",
|
output: "021_mjs_modules.ts.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(_022_info_flag_script {
|
itest!(_022_info_flag_script {
|
||||||
args: "info http://127.0.0.1:4545/cli/tests/019_media_types.ts",
|
args: "info http://127.0.0.1:4545/cli/tests/019_media_types.ts",
|
||||||
output: "022_info_flag_script.out",
|
output: "022_info_flag_script.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
itest!(_023_no_ext_with_headers {
|
itest!(_023_no_ext_with_headers {
|
||||||
args: "run --reload 023_no_ext_with_headers",
|
args: "run --reload 023_no_ext_with_headers",
|
||||||
|
@ -335,21 +331,17 @@ itest!(_047_jsx {
|
||||||
output: "047_jsx_test.jsx.out",
|
output: "047_jsx_test.jsx.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(_048_media_types_jsx {
|
itest!(_048_media_types_jsx {
|
||||||
args: "run --reload 048_media_types_jsx.ts",
|
args: "run --reload 048_media_types_jsx.ts",
|
||||||
output: "048_media_types_jsx.ts.out",
|
output: "048_media_types_jsx.ts.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(_049_info_flag_script_jsx {
|
itest!(_049_info_flag_script_jsx {
|
||||||
args: "info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts",
|
args: "info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts",
|
||||||
output: "049_info_flag_script_jsx.out",
|
output: "049_info_flag_script_jsx.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
itest!(_050_more_jsons {
|
itest!(_050_more_jsons {
|
||||||
args: "run --reload 050_more_jsons.ts",
|
args: "run --reload 050_more_jsons.ts",
|
||||||
|
@ -362,13 +354,11 @@ itest!(lock_check_ok {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(lock_check_ok2 {
|
itest!(lock_check_ok2 {
|
||||||
args: "run 019_media_types.ts --lock=lock_check_ok2.json",
|
args: "run 019_media_types.ts --lock=lock_check_ok2.json",
|
||||||
output: "019_media_types.ts.out",
|
output: "019_media_types.ts.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
itest!(lock_check_err {
|
itest!(lock_check_err {
|
||||||
args: "run --lock=lock_check_err.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts",
|
args: "run --lock=lock_check_err.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts",
|
||||||
|
@ -378,7 +368,6 @@ itest!(lock_check_err {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO(ry) Re-enable this test. It is flaky and only fails occasionally.
|
|
||||||
itest!(lock_check_err2 {
|
itest!(lock_check_err2 {
|
||||||
args: "run 019_media_types.ts --lock=lock_check_err2.json",
|
args: "run 019_media_types.ts --lock=lock_check_err2.json",
|
||||||
output: "lock_check_err2.out",
|
output: "lock_check_err2.out",
|
||||||
|
@ -386,7 +375,6 @@ itest!(lock_check_err2 {
|
||||||
exit_code: 10,
|
exit_code: 10,
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
itest!(async_error {
|
itest!(async_error {
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
|
Loading…
Reference in a new issue