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

test: add utility function for assigning unique port to inspector (#5822)

This commit is contained in:
Bert Belder 2020-05-25 02:08:59 +02:00
parent e934df5f7d
commit ee0b5bb89e
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -2207,6 +2207,13 @@ fn test_permissions_net_listen_allow_localhost() {
assert!(!err.contains(util::PERMISSION_DENIED_PATTERN)); assert!(!err.contains(util::PERMISSION_DENIED_PATTERN));
} }
fn inspect_flag_with_unique_port(flag_prefix: &str) -> String {
use std::sync::atomic::{AtomicU16, Ordering};
static PORT: AtomicU16 = AtomicU16::new(9229);
let port = PORT.fetch_add(1, Ordering::Relaxed);
format!("{}=127.0.0.1:{}", flag_prefix, port)
}
fn extract_ws_url_from_stderr( fn extract_ws_url_from_stderr(
stderr: &mut std::process::ChildStderr, stderr: &mut std::process::ChildStderr,
) -> url::Url { ) -> url::Url {
@ -2226,9 +2233,7 @@ async fn inspector_connect() {
let script = util::tests_path().join("inspector1.js"); let script = util::tests_path().join("inspector1.js");
let mut child = util::deno_cmd() let mut child = util::deno_cmd()
.arg("run") .arg("run")
// Warning: each inspector test should be on its own port to avoid .arg(inspect_flag_with_unique_port("--inspect"))
// conflicting with another inspector test.
.arg("--inspect=127.0.0.1:9228")
.arg(script) .arg(script)
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
.spawn() .spawn()
@ -2256,9 +2261,7 @@ async fn inspector_break_on_first_line() {
let script = util::tests_path().join("inspector2.js"); let script = util::tests_path().join("inspector2.js");
let mut child = util::deno_cmd() let mut child = util::deno_cmd()
.arg("run") .arg("run")
// Warning: each inspector test should be on its own port to avoid .arg(inspect_flag_with_unique_port("--inspect-brk"))
// conflicting with another inspector test.
.arg("--inspect-brk=127.0.0.1:9229")
.arg(script) .arg(script)
.stdout(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
@ -2322,9 +2325,7 @@ async fn inspector_pause() {
let script = util::tests_path().join("inspector1.js"); let script = util::tests_path().join("inspector1.js");
let mut child = util::deno_cmd() let mut child = util::deno_cmd()
.arg("run") .arg("run")
// Warning: each inspector test should be on its own port to avoid .arg(inspect_flag_with_unique_port("--inspect"))
// conflicting with another inspector test.
.arg("--inspect=127.0.0.1:9230")
.arg(script) .arg(script)
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
.spawn() .spawn()
@ -2376,9 +2377,11 @@ async fn inspector_pause() {
#[tokio::test] #[tokio::test]
async fn inspector_port_collision() { async fn inspector_port_collision() {
let script = util::tests_path().join("inspector1.js"); let script = util::tests_path().join("inspector1.js");
let inspect_flag = inspect_flag_with_unique_port("--inspect");
let mut child1 = util::deno_cmd() let mut child1 = util::deno_cmd()
.arg("run") .arg("run")
.arg("--inspect=127.0.0.1:9231") .arg(&inspect_flag)
.arg(script.clone()) .arg(script.clone())
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
.spawn() .spawn()
@ -2388,7 +2391,7 @@ async fn inspector_port_collision() {
let mut child2 = util::deno_cmd() let mut child2 = util::deno_cmd()
.arg("run") .arg("run")
.arg("--inspect=127.0.0.1:9231") .arg(&inspect_flag)
.arg(script) .arg(script)
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())
.spawn() .spawn()
@ -2414,9 +2417,7 @@ async fn inspector_does_not_hang() {
let script = util::tests_path().join("inspector3.js"); let script = util::tests_path().join("inspector3.js");
let mut child = util::deno_cmd() let mut child = util::deno_cmd()
.arg("run") .arg("run")
// Warning: each inspector test should be on its own port to avoid .arg(inspect_flag_with_unique_port("--inspect-brk"))
// conflicting with another inspector test.
.arg("--inspect-brk=127.0.0.1:9232")
.env("NO_COLOR", "1") .env("NO_COLOR", "1")
.arg(script) .arg(script)
.stdout(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())
@ -2498,9 +2499,7 @@ async fn inspector_without_brk_runs_code() {
let script = util::tests_path().join("inspector4.js"); let script = util::tests_path().join("inspector4.js");
let mut child = util::deno_cmd() let mut child = util::deno_cmd()
.arg("run") .arg("run")
// Warning: each inspector test should be on its own port to avoid .arg(inspect_flag_with_unique_port("--inspect"))
// conflicting with another inspector test.
.arg("--inspect=127.0.0.1:9233")
.arg(script) .arg(script)
.stdout(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped())