Skip to content

Commit

Permalink
Auto merge of #11356 - arlosi:sparse-publish, r=epage
Browse files Browse the repository at this point in the history
Fix wait-for-publish with sparse registry

The `wait-for-publish` feature doesn't work when publishing a new version of an existing crate on a sparse registry.

The `invalidate_cache` method doesn't clear the `fresh` list, so repeated requests just use the in-memory data if it's available. This didn't show up in the tests, because the test only simulated the `not found` to `crate available` transition, rather than the `old file` to `crate available` transition.

This change modifies the test by capturing the publish request, then deferring it until after later request for the index file.

r? `@epage`

Fixes #11314
  • Loading branch information
bors committed Nov 9, 2022
2 parents 5ccea51 + 90c6b58 commit 0756938
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit 0756938

Please sign in to comment.