From 90c6b5854d64303b7d772405e140333823c5a398 Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Tue, 8 Nov 2022 18:14:52 -0600 Subject: [PATCH] Fix waiting for publishing to complete when publishing to a sparse registry --- crates/cargo-test-support/src/registry.rs | 1 + src/cargo/sources/registry/http_remote.rs | 1 + tests/testsuite/publish.rs | 17 +++++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 17a90e8f6be..1f30ea01134 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -469,6 +469,7 @@ impl Drop for HttpServerHandle { } /// Request to the test http server +#[derive(Clone)] pub struct Request { pub url: Url, pub method: String, diff --git a/src/cargo/sources/registry/http_remote.rs b/src/cargo/sources/registry/http_remote.rs index e659cb3ccfe..805942274c0 100644 --- a/src/cargo/sources/registry/http_remote.rs +++ b/src/cargo/sources/registry/http_remote.rs @@ -549,6 +549,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> { // All it does is ensure that a subsequent load will double-check files with the // server rather than rely on a locally cached copy of the index files. debug!("invalidated index cache"); + self.fresh.clear(); self.requested_update = true; } diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 8a0e0255933..aed1aa396a4 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -2570,20 +2570,25 @@ fn wait_for_subsequent_publish() { // Counter for number of tries before the package is "published" let arc: Arc> = Arc::new(Mutex::new(0)); let arc2 = arc.clone(); + let publish_req = Arc::new(Mutex::new(None)); + let publish_req2 = publish_req.clone(); - // Registry returns an invalid response. let registry = registry::RegistryBuilder::new() .http_index() .http_api() + .add_responder("/api/v1/crates/new", move |req, server| { + // Capture the publish request, but defer publishing + *publish_req.lock().unwrap() = Some(req.clone()); + server.ok(req) + }) .add_responder("/index/de/la/delay", move |req, server| { let mut lock = arc.lock().unwrap(); *lock += 1; - // if the package name contains _ or - - if *lock <= 2 { - server.not_found(req) - } else { - server.index(req) + if *lock == 3 { + // Run the publish on the 3rd attempt + server.publish(&publish_req2.lock().unwrap().as_ref().unwrap()); } + server.index(req) }) .build();