1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

fix(inspector): proper error message on port collision (#4514)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2020-03-28 14:42:29 -07:00 committed by GitHub
parent ad198b1cf1
commit 2f7842246e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View file

@ -283,7 +283,12 @@ async fn server(address: SocketAddrV4, mut server_msg_rx: ServerMsgRx) {
});
let routes = websocket.or(version).or(json_list);
let web_handler = warp::serve(routes).bind(address);
let (_, web_handler) = warp::serve(routes)
.try_bind_ephemeral(address)
.unwrap_or_else(|e| {
eprintln!("Cannot start inspector server: {}", e);
std::process::exit(1);
});
future::join(msg_handler, web_handler).await;
}

View file

@ -2072,6 +2072,44 @@ async fn inspector_pause() {
child.kill().unwrap();
}
#[cfg(not(target_os = "linux"))] // TODO(ry) broken on github actions.
#[tokio::test]
async fn inspector_port_collision() {
let script = deno::test_util::root_path()
.join("cli")
.join("tests")
.join("inspector1.js");
let mut child1 = util::deno_cmd()
.arg("run")
.arg("--inspect=127.0.0.1:9231")
.arg(script.clone())
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap();
let ws_url_1 = extract_ws_url_from_stderr(child1.stderr.as_mut().unwrap());
println!("ws_url {}", ws_url_1);
let mut child2 = util::deno_cmd()
.arg("run")
.arg("--inspect=127.0.0.1:9231")
.arg(script)
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap();
use std::io::Read;
let mut stderr_str_2 = String::new();
child2
.stderr
.as_mut()
.unwrap()
.read_to_string(&mut stderr_str_2)
.unwrap();
assert!(stderr_str_2.contains("Cannot start inspector server"));
child1.kill().unwrap();
let _ = child2.kill();
}
mod util {
use deno::colors::strip_ansi_codes;
pub use deno::test_util::*;