Skip to content

Commit 6cf01b8

Browse files
committed
Auto merge of #11360 - arlosi:beta-sparse-wait, r=epage
[BETA-1.66] Fix wait-for-publish with sparse registry Beta backport of #11356 r? `@epage`
2 parents 7e484fc + f0105c2 commit 6cf01b8

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ impl Drop for HttpServerHandle {
469469
}
470470

471471
/// Request to the test http server
472+
#[derive(Clone)]
472473
pub struct Request {
473474
pub url: Url,
474475
pub method: String,

src/cargo/sources/registry/http_remote.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
549549
// All it does is ensure that a subsequent load will double-check files with the
550550
// server rather than rely on a locally cached copy of the index files.
551551
debug!("invalidated index cache");
552+
self.fresh.clear();
552553
self.requested_update = true;
553554
}
554555

tests/testsuite/publish.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,97 @@ See [..]
25472547
.run();
25482548
}
25492549

2550+
#[cargo_test]
2551+
fn wait_for_subsequent_publish() {
2552+
// Counter for number of tries before the package is "published"
2553+
let arc: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
2554+
let arc2 = arc.clone();
2555+
let publish_req = Arc::new(Mutex::new(None));
2556+
let publish_req2 = publish_req.clone();
2557+
2558+
let registry = registry::RegistryBuilder::new()
2559+
.http_index()
2560+
.http_api()
2561+
.add_responder("/api/v1/crates/new", move |req, server| {
2562+
// Capture the publish request, but defer publishing
2563+
*publish_req.lock().unwrap() = Some(req.clone());
2564+
server.ok(req)
2565+
})
2566+
.add_responder("/index/de/la/delay", move |req, server| {
2567+
let mut lock = arc.lock().unwrap();
2568+
*lock += 1;
2569+
if *lock == 3 {
2570+
// Run the publish on the 3rd attempt
2571+
server.publish(&publish_req2.lock().unwrap().as_ref().unwrap());
2572+
}
2573+
server.index(req)
2574+
})
2575+
.build();
2576+
2577+
// Publish an earlier version
2578+
Package::new("delay", "0.0.1")
2579+
.file("src/lib.rs", "")
2580+
.publish();
2581+
2582+
let p = project()
2583+
.file(
2584+
"Cargo.toml",
2585+
r#"
2586+
[package]
2587+
name = "delay"
2588+
version = "0.0.2"
2589+
authors = []
2590+
license = "MIT"
2591+
description = "foo"
2592+
2593+
"#,
2594+
)
2595+
.file("src/lib.rs", "")
2596+
.build();
2597+
2598+
p.cargo("publish --no-verify -Z sparse-registry")
2599+
.masquerade_as_nightly_cargo(&["sparse-registry"])
2600+
.replace_crates_io(registry.index_url())
2601+
.with_status(0)
2602+
.with_stderr(
2603+
"\
2604+
[UPDATING] crates.io index
2605+
[WARNING] manifest has no documentation, [..]
2606+
See [..]
2607+
[PACKAGING] delay v0.0.2 ([CWD])
2608+
[UPLOADING] delay v0.0.2 ([CWD])
2609+
[UPDATING] crates.io index
2610+
[WAITING] on `delay` to propagate to crates.io index (ctrl-c to wait asynchronously)
2611+
",
2612+
)
2613+
.run();
2614+
2615+
// Verify the responder has been pinged
2616+
let lock = arc2.lock().unwrap();
2617+
assert_eq!(*lock, 3);
2618+
drop(lock);
2619+
2620+
let p = project()
2621+
.file(
2622+
"Cargo.toml",
2623+
r#"
2624+
[package]
2625+
name = "foo"
2626+
version = "0.0.1"
2627+
authors = []
2628+
[dependencies]
2629+
delay = "0.0.2"
2630+
"#,
2631+
)
2632+
.file("src/main.rs", "fn main() {}")
2633+
.build();
2634+
2635+
p.cargo("build -Z sparse-registry")
2636+
.masquerade_as_nightly_cargo(&["sparse-registry"])
2637+
.with_status(0)
2638+
.run();
2639+
}
2640+
25502641
#[cargo_test]
25512642
fn skip_wait_for_publish() {
25522643
// Intentionally using local registry so the crate never makes it to the index

0 commit comments

Comments
 (0)