Skip to content

Commit 688ec9e

Browse files
ojuschugh1epage
authored andcommitted
test(publish): Add test demonstrating error messages during workspace publish rate limiting
1 parent 623d536 commit 688ec9e

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

tests/testsuite/publish.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,3 +4402,106 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
44024402
"#]])
44034403
.run();
44044404
}
4405+
4406+
#[cargo_test]
4407+
fn workspace_publish_rate_limit_error() {
4408+
let registry = registry::RegistryBuilder::new()
4409+
.http_api()
4410+
.http_index()
4411+
.add_responder("/api/v1/crates/new", |_req, _| {
4412+
// For simplicity, let's just return rate limit error for all requests
4413+
// This simulates hitting rate limit during workspace publish
4414+
Response {
4415+
code: 429,
4416+
headers: vec!["Retry-After: 3600".to_string()],
4417+
body: format!(
4418+
"You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email [email protected] to have your limit increased."
4419+
).into_bytes(),
4420+
}
4421+
})
4422+
.build();
4423+
4424+
let p = project()
4425+
.file(
4426+
"Cargo.toml",
4427+
r#"
4428+
[workspace]
4429+
members = ["package_a", "package_b", "package_c"]
4430+
"#,
4431+
)
4432+
.file("src/lib.rs", "")
4433+
.file(
4434+
"package_a/Cargo.toml",
4435+
r#"
4436+
[package]
4437+
name = "package_a"
4438+
version = "0.1.0"
4439+
edition = "2015"
4440+
license = "MIT"
4441+
description = "package a"
4442+
repository = "https://github.com/test/package_a"
4443+
"#,
4444+
)
4445+
.file("package_a/src/lib.rs", "")
4446+
.file(
4447+
"package_b/Cargo.toml",
4448+
r#"
4449+
[package]
4450+
name = "package_b"
4451+
version = "0.1.0"
4452+
edition = "2015"
4453+
license = "MIT"
4454+
description = "package b"
4455+
repository = "https://github.com/test/package_b"
4456+
"#,
4457+
)
4458+
.file("package_b/src/lib.rs", "")
4459+
.file(
4460+
"package_c/Cargo.toml",
4461+
r#"
4462+
[package]
4463+
name = "package_c"
4464+
version = "0.1.0"
4465+
edition = "2015"
4466+
license = "MIT"
4467+
description = "package c"
4468+
repository = "https://github.com/test/package_c"
4469+
4470+
[dependencies]
4471+
package_a = { version = "0.1.0", path = "../package_a" }
4472+
"#,
4473+
)
4474+
.file("package_c/src/lib.rs", "")
4475+
.build();
4476+
4477+
// This demonstrates the current non-actionable error message
4478+
// The user doesn't know which package failed or what packages remain to be published
4479+
p.cargo("publish --workspace --no-verify")
4480+
.replace_crates_io(registry.index_url())
4481+
.with_status(101)
4482+
.with_stderr_data(str![[r#"
4483+
[UPDATING] crates.io index
4484+
[PACKAGING] package_a v0.1.0 ([ROOT]/foo/package_a)
4485+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4486+
[PACKAGING] package_b v0.1.0 ([ROOT]/foo/package_b)
4487+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4488+
[PACKAGING] package_c v0.1.0 ([ROOT]/foo/package_c)
4489+
[UPDATING] crates.io index
4490+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4491+
[UPLOADING] package_a v0.1.0 ([ROOT]/foo/package_a)
4492+
[ERROR] failed to publish to registry at http://127.0.0.1:[..]/
4493+
4494+
Caused by:
4495+
failed to get a 200 OK response, got 429
4496+
headers:
4497+
HTTP/1.1 429
4498+
Content-Length: 172
4499+
Connection: close
4500+
Retry-After: 3600
4501+
4502+
body:
4503+
You have published too many new crates in a short period of time. Please try again after Fri, 18 Jul 2025 20:00:34 GMT or email [email protected] to have your limit increased.
4504+
4505+
"#]])
4506+
.run();
4507+
}

0 commit comments

Comments
 (0)