Skip to content

Commit 0756938

Browse files
committed
Auto merge of #11356 - arlosi:sparse-publish, r=epage
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
2 parents 5ccea51 + 90c6b58 commit 0756938

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,20 +2570,25 @@ fn wait_for_subsequent_publish() {
25702570
// Counter for number of tries before the package is "published"
25712571
let arc: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
25722572
let arc2 = arc.clone();
2573+
let publish_req = Arc::new(Mutex::new(None));
2574+
let publish_req2 = publish_req.clone();
25732575

2574-
// Registry returns an invalid response.
25752576
let registry = registry::RegistryBuilder::new()
25762577
.http_index()
25772578
.http_api()
2579+
.add_responder("/api/v1/crates/new", move |req, server| {
2580+
// Capture the publish request, but defer publishing
2581+
*publish_req.lock().unwrap() = Some(req.clone());
2582+
server.ok(req)
2583+
})
25782584
.add_responder("/index/de/la/delay", move |req, server| {
25792585
let mut lock = arc.lock().unwrap();
25802586
*lock += 1;
2581-
// if the package name contains _ or -
2582-
if *lock <= 2 {
2583-
server.not_found(req)
2584-
} else {
2585-
server.index(req)
2587+
if *lock == 3 {
2588+
// Run the publish on the 3rd attempt
2589+
server.publish(&publish_req2.lock().unwrap().as_ref().unwrap());
25862590
}
2591+
server.index(req)
25872592
})
25882593
.build();
25892594

0 commit comments

Comments
 (0)