Skip to content

Commit

Permalink
chore: serve node headers from a test server to fix flaky node-gyp
Browse files Browse the repository at this point in the history
…test (#26749)

Fixes #24749

Runs a server that just returns the header tarball and checksum, and
sets the `NODEJS_ORG_MIRROR` env var so that `node-gyp` uses it instead
of `nodejs.org`
  • Loading branch information
nathanwhit authored and littledivy committed Nov 10, 2024
1 parent 8441aef commit 6f73b98
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/registry/npm/@denotest/node-addon/1.0.0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@denotest/node-addon",
"version": "1.0.0",
"scripts": {
"install": "node-gyp configure build"
"install": "node-gyp configure --verbose build"
},
"dependencies": {
"node-gyp": "10.1.0"
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/util/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bytes.workspace = true
console_static_text.workspace = true
deno_unsync = "0"
denokv_proto.workspace = true
faster-hex.workspace = true
fastwebsockets.workspace = true
flate2 = { workspace = true, features = ["default"] }
futures.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions tests/util/server/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::fs::PathRef;
use crate::http_server;
use crate::jsr_registry_unset_url;
use crate::lsp::LspClientBuilder;
use crate::nodejs_org_mirror_unset_url;
use crate::npm_registry_unset_url;
use crate::pty::Pty;
use crate::strip_ansi_codes;
Expand Down Expand Up @@ -843,6 +844,12 @@ impl TestCommandBuilder {
if !envs.contains_key("JSR_URL") {
envs.insert("JSR_URL".to_string(), jsr_registry_unset_url());
}
if !envs.contains_key("NODEJS_ORG_MIRROR") {
envs.insert(
"NODEJS_ORG_MIRROR".to_string(),
nodejs_org_mirror_unset_url(),
);
}
for key in &self.envs_remove {
envs.remove(key);
}
Expand Down
29 changes: 23 additions & 6 deletions tests/util/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static GUARD: Lazy<Mutex<HttpServerCount>> = Lazy::new(Default::default);
pub fn env_vars_for_npm_tests() -> Vec<(String, String)> {
vec![
("NPM_CONFIG_REGISTRY".to_string(), npm_registry_url()),
("NODEJS_ORG_MIRROR".to_string(), nodejs_org_mirror_url()),
("NO_COLOR".to_string(), "1".to_string()),
]
}
Expand Down Expand Up @@ -130,6 +131,7 @@ pub fn env_vars_for_jsr_npm_tests() -> Vec<(String, String)> {
),
("DISABLE_JSR_PROVENANCE".to_string(), "true".to_string()),
("NO_COLOR".to_string(), "1".to_string()),
("NODEJS_ORG_MIRROR".to_string(), nodejs_org_mirror_url()),
]
}

Expand Down Expand Up @@ -175,27 +177,41 @@ pub fn deno_config_path() -> PathRef {

/// Test server registry url.
pub fn npm_registry_url() -> String {
"http://localhost:4260/".to_string()
format!("http://localhost:{}/", servers::PUBLIC_NPM_REGISTRY_PORT)
}

pub fn npm_registry_unset_url() -> String {
"http://NPM_CONFIG_REGISTRY.is.unset".to_string()
}

pub fn nodejs_org_mirror_url() -> String {
format!(
"http://127.0.0.1:{}/",
servers::NODEJS_ORG_MIRROR_SERVER_PORT
)
}

pub fn nodejs_org_mirror_unset_url() -> String {
"http://NODEJS_ORG_MIRROR.is.unset".to_string()
}

pub fn jsr_registry_url() -> String {
"http://127.0.0.1:4250/".to_string()
format!("http://127.0.0.1:{}/", servers::JSR_REGISTRY_SERVER_PORT)
}

pub fn rekor_url() -> String {
"http://127.0.0.1:4251".to_string()
format!("http://127.0.0.1:{}", servers::PROVENANCE_MOCK_SERVER_PORT)
}

pub fn fulcio_url() -> String {
"http://127.0.0.1:4251".to_string()
format!("http://127.0.0.1:{}", servers::PROVENANCE_MOCK_SERVER_PORT)
}

pub fn gha_token_url() -> String {
"http://127.0.0.1:4251/gha_oidc?test=true".to_string()
format!(
"http://127.0.0.1:{}/gha_oidc?test=true",
servers::PROVENANCE_MOCK_SERVER_PORT
)
}

pub fn jsr_registry_unset_url() -> String {
Expand Down Expand Up @@ -307,7 +323,7 @@ async fn get_tcp_listener_stream(
futures::stream::select_all(listeners)
}

pub const TEST_SERVERS_COUNT: usize = 32;
pub const TEST_SERVERS_COUNT: usize = 33;

#[derive(Default)]
struct HttpServerCount {
Expand Down Expand Up @@ -565,6 +581,7 @@ pub fn deno_cmd_with_deno_dir(deno_dir: &TempDir) -> TestCommandBuilder {
TestCommandBuilder::new(deno_dir.clone())
.env("DENO_DIR", deno_dir.path())
.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url())
.env("NODEJS_ORG_MIRROR", nodejs_org_mirror_unset_url())
.env("JSR_URL", jsr_registry_unset_url())
}

Expand Down
11 changes: 9 additions & 2 deletions tests/util/server/src/servers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use tokio::net::TcpStream;
mod grpc;
mod hyper_utils;
mod jsr_registry;
mod nodejs_org_mirror;
mod npm_registry;
mod ws;

Expand Down Expand Up @@ -86,8 +87,9 @@ const WS_CLOSE_PORT: u16 = 4244;
const WS_PING_PORT: u16 = 4245;
const H2_GRPC_PORT: u16 = 4246;
const H2S_GRPC_PORT: u16 = 4247;
const JSR_REGISTRY_SERVER_PORT: u16 = 4250;
const PROVENANCE_MOCK_SERVER_PORT: u16 = 4251;
pub(crate) const JSR_REGISTRY_SERVER_PORT: u16 = 4250;
pub(crate) const PROVENANCE_MOCK_SERVER_PORT: u16 = 4251;
pub(crate) const NODEJS_ORG_MIRROR_SERVER_PORT: u16 = 4252;
pub(crate) const PUBLIC_NPM_REGISTRY_PORT: u16 = 4260;
pub(crate) const PRIVATE_NPM_REGISTRY_1_PORT: u16 = 4261;
pub(crate) const PRIVATE_NPM_REGISTRY_2_PORT: u16 = 4262;
Expand Down Expand Up @@ -147,6 +149,10 @@ pub async fn run_all_servers() {
let private_npm_registry_3_server_futs =
npm_registry::private_npm_registry3(PRIVATE_NPM_REGISTRY_3_PORT);

// for serving node header files to node-gyp in tests
let node_js_mirror_server_fut =
nodejs_org_mirror::nodejs_org_mirror(NODEJS_ORG_MIRROR_SERVER_PORT);

let mut futures = vec![
redirect_server_fut.boxed_local(),
ws_server_fut.boxed_local(),
Expand All @@ -172,6 +178,7 @@ pub async fn run_all_servers() {
h2_grpc_server_fut.boxed_local(),
registry_server_fut.boxed_local(),
provenance_mock_server_fut.boxed_local(),
node_js_mirror_server_fut.boxed_local(),
];
futures.extend(npm_registry_server_futs);
futures.extend(private_npm_registry_1_server_futs);
Expand Down
Loading

0 comments on commit 6f73b98

Please sign in to comment.