Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wait-for-publish with sparse registry #11356

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/sources/registry/http_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 11 additions & 6 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2570,20 +2570,25 @@ fn wait_for_subsequent_publish() {
// Counter for number of tries before the package is "published"
let arc: Arc<Mutex<u32>> = 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();

Expand Down