Skip to content

Commit 742744d

Browse files
authored
chore: serve node headers from a test server to fix flaky node-gyp test (denoland#26749)
Fixes denoland#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`
1 parent 1cab4f0 commit 742744d

File tree

9 files changed

+287
-9
lines changed

9 files changed

+287
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/registry/npm/@denotest/node-addon/1.0.0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@denotest/node-addon",
33
"version": "1.0.0",
44
"scripts": {
5-
"install": "node-gyp configure build"
5+
"install": "node-gyp configure --verbose build"
66
},
77
"dependencies": {
88
"node-gyp": "10.1.0"
303 KB
Binary file not shown.
Binary file not shown.

tests/util/server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bytes.workspace = true
2121
console_static_text.workspace = true
2222
deno_unsync = "0"
2323
denokv_proto.workspace = true
24+
faster-hex.workspace = true
2425
fastwebsockets.workspace = true
2526
flate2 = { workspace = true, features = ["default"] }
2627
futures.workspace = true

tests/util/server/src/builders.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::fs::PathRef;
2828
use crate::http_server;
2929
use crate::jsr_registry_unset_url;
3030
use crate::lsp::LspClientBuilder;
31+
use crate::nodejs_org_mirror_unset_url;
3132
use crate::npm_registry_unset_url;
3233
use crate::pty::Pty;
3334
use crate::strip_ansi_codes;
@@ -843,6 +844,12 @@ impl TestCommandBuilder {
843844
if !envs.contains_key("JSR_URL") {
844845
envs.insert("JSR_URL".to_string(), jsr_registry_unset_url());
845846
}
847+
if !envs.contains_key("NODEJS_ORG_MIRROR") {
848+
envs.insert(
849+
"NODEJS_ORG_MIRROR".to_string(),
850+
nodejs_org_mirror_unset_url(),
851+
);
852+
}
846853
for key in &self.envs_remove {
847854
envs.remove(key);
848855
}

tests/util/server/src/lib.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static GUARD: Lazy<Mutex<HttpServerCount>> = Lazy::new(Default::default);
5252
pub fn env_vars_for_npm_tests() -> Vec<(String, String)> {
5353
vec![
5454
("NPM_CONFIG_REGISTRY".to_string(), npm_registry_url()),
55+
("NODEJS_ORG_MIRROR".to_string(), nodejs_org_mirror_url()),
5556
("NO_COLOR".to_string(), "1".to_string()),
5657
]
5758
}
@@ -130,6 +131,7 @@ pub fn env_vars_for_jsr_npm_tests() -> Vec<(String, String)> {
130131
),
131132
("DISABLE_JSR_PROVENANCE".to_string(), "true".to_string()),
132133
("NO_COLOR".to_string(), "1".to_string()),
134+
("NODEJS_ORG_MIRROR".to_string(), nodejs_org_mirror_url()),
133135
]
134136
}
135137

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

176178
/// Test server registry url.
177179
pub fn npm_registry_url() -> String {
178-
"http://localhost:4260/".to_string()
180+
format!("http://localhost:{}/", servers::PUBLIC_NPM_REGISTRY_PORT)
179181
}
180182

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

187+
pub fn nodejs_org_mirror_url() -> String {
188+
format!(
189+
"http://127.0.0.1:{}/",
190+
servers::NODEJS_ORG_MIRROR_SERVER_PORT
191+
)
192+
}
193+
194+
pub fn nodejs_org_mirror_unset_url() -> String {
195+
"http://NODEJS_ORG_MIRROR.is.unset".to_string()
196+
}
197+
185198
pub fn jsr_registry_url() -> String {
186-
"http://127.0.0.1:4250/".to_string()
199+
format!("http://127.0.0.1:{}/", servers::JSR_REGISTRY_SERVER_PORT)
187200
}
188201

189202
pub fn rekor_url() -> String {
190-
"http://127.0.0.1:4251".to_string()
203+
format!("http://127.0.0.1:{}", servers::PROVENANCE_MOCK_SERVER_PORT)
191204
}
192205

193206
pub fn fulcio_url() -> String {
194-
"http://127.0.0.1:4251".to_string()
207+
format!("http://127.0.0.1:{}", servers::PROVENANCE_MOCK_SERVER_PORT)
195208
}
196209

197210
pub fn gha_token_url() -> String {
198-
"http://127.0.0.1:4251/gha_oidc?test=true".to_string()
211+
format!(
212+
"http://127.0.0.1:{}/gha_oidc?test=true",
213+
servers::PROVENANCE_MOCK_SERVER_PORT
214+
)
199215
}
200216

201217
pub fn jsr_registry_unset_url() -> String {
@@ -307,7 +323,7 @@ async fn get_tcp_listener_stream(
307323
futures::stream::select_all(listeners)
308324
}
309325

310-
pub const TEST_SERVERS_COUNT: usize = 32;
326+
pub const TEST_SERVERS_COUNT: usize = 33;
311327

312328
#[derive(Default)]
313329
struct HttpServerCount {
@@ -565,6 +581,7 @@ pub fn deno_cmd_with_deno_dir(deno_dir: &TempDir) -> TestCommandBuilder {
565581
TestCommandBuilder::new(deno_dir.clone())
566582
.env("DENO_DIR", deno_dir.path())
567583
.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url())
584+
.env("NODEJS_ORG_MIRROR", nodejs_org_mirror_unset_url())
568585
.env("JSR_URL", jsr_registry_unset_url())
569586
}
570587

tests/util/server/src/servers/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use tokio::net::TcpStream;
3939
mod grpc;
4040
mod hyper_utils;
4141
mod jsr_registry;
42+
mod nodejs_org_mirror;
4243
mod npm_registry;
4344
mod ws;
4445

@@ -86,8 +87,9 @@ const WS_CLOSE_PORT: u16 = 4244;
8687
const WS_PING_PORT: u16 = 4245;
8788
const H2_GRPC_PORT: u16 = 4246;
8889
const H2S_GRPC_PORT: u16 = 4247;
89-
const JSR_REGISTRY_SERVER_PORT: u16 = 4250;
90-
const PROVENANCE_MOCK_SERVER_PORT: u16 = 4251;
90+
pub(crate) const JSR_REGISTRY_SERVER_PORT: u16 = 4250;
91+
pub(crate) const PROVENANCE_MOCK_SERVER_PORT: u16 = 4251;
92+
pub(crate) const NODEJS_ORG_MIRROR_SERVER_PORT: u16 = 4252;
9193
pub(crate) const PUBLIC_NPM_REGISTRY_PORT: u16 = 4260;
9294
pub(crate) const PRIVATE_NPM_REGISTRY_1_PORT: u16 = 4261;
9395
pub(crate) const PRIVATE_NPM_REGISTRY_2_PORT: u16 = 4262;
@@ -147,6 +149,10 @@ pub async fn run_all_servers() {
147149
let private_npm_registry_3_server_futs =
148150
npm_registry::private_npm_registry3(PRIVATE_NPM_REGISTRY_3_PORT);
149151

152+
// for serving node header files to node-gyp in tests
153+
let node_js_mirror_server_fut =
154+
nodejs_org_mirror::nodejs_org_mirror(NODEJS_ORG_MIRROR_SERVER_PORT);
155+
150156
let mut futures = vec![
151157
redirect_server_fut.boxed_local(),
152158
ws_server_fut.boxed_local(),
@@ -172,6 +178,7 @@ pub async fn run_all_servers() {
172178
h2_grpc_server_fut.boxed_local(),
173179
registry_server_fut.boxed_local(),
174180
provenance_mock_server_fut.boxed_local(),
181+
node_js_mirror_server_fut.boxed_local(),
175182
];
176183
futures.extend(npm_registry_server_futs);
177184
futures.extend(private_npm_registry_1_server_futs);

0 commit comments

Comments
 (0)