Skip to content

Commit

Permalink
Auto merge of #11327 - epage:wait, r=ehuss
Browse files Browse the repository at this point in the history
test(publish): Cover more wait-for-publish cases

These came from trying to guess what cases are causing problems in #11314.  Unfortunately, can't reproduce it so far but figured it'd be good to keep these around.
  • Loading branch information
bors committed Nov 4, 2022
2 parents 7d8d028 + d87966b commit 68e9d6c
Showing 1 changed file with 89 additions and 14 deletions.
103 changes: 89 additions & 14 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ fn http_api_not_noop() {
}

#[cargo_test]
fn wait_for_publish() {
fn wait_for_first_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();
Expand All @@ -2419,12 +2419,6 @@ fn wait_for_publish() {
})
.build();

// The sparse-registry test server does not know how to publish on its own.
// So let us call publish for it.
Package::new("delay", "0.0.1")
.file("src/lib.rs", "")
.publish();

let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -2489,7 +2483,7 @@ See [..]
/// the responder twice per cargo invocation. If that ever gets changed
/// this test will need to be changed accordingly.
#[cargo_test]
fn wait_for_publish_underscore() {
fn wait_for_first_publish_underscore() {
// Counter for number of tries before the package is "published"
let arc: Arc<Mutex<u32>> = Arc::new(Mutex::new(0));
let arc2 = arc.clone();
Expand All @@ -2510,12 +2504,6 @@ fn wait_for_publish_underscore() {
})
.build();

// The sparse-registry test server does not know how to publish on its own.
// So let us call publish for it.
Package::new("delay_with_underscore", "0.0.1")
.file("src/lib.rs", "")
.publish();

let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -2577,6 +2565,93 @@ See [..]
.run();
}

#[cargo_test]
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();

// Registry returns an invalid response.
let registry = registry::RegistryBuilder::new()
.http_index()
.http_api()
.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)
}
})
.build();

// Publish an earlier version
Package::new("delay", "0.0.1")
.file("src/lib.rs", "")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "delay"
version = "0.0.2"
authors = []
license = "MIT"
description = "foo"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("publish --no-verify -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.replace_crates_io(registry.index_url())
.with_status(0)
.with_stderr(
"\
[UPDATING] crates.io index
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] delay v0.0.2 ([CWD])
[PACKAGED] [..] files, [..] ([..] compressed)
[UPLOADING] delay v0.0.2 ([CWD])
[UPDATING] crates.io index
[WAITING] on `delay` to propagate to crates.io index (ctrl-c to wait asynchronously)
",
)
.run();

// Verify the responder has been pinged
let lock = arc2.lock().unwrap();
assert_eq!(*lock, 3);
drop(lock);

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
delay = "0.0.2"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("build -Z sparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.with_status(0)
.run();
}

#[cargo_test]
fn skip_wait_for_publish() {
// Intentionally using local registry so the crate never makes it to the index
Expand Down

0 comments on commit 68e9d6c

Please sign in to comment.