Skip to content

Commit

Permalink
test(publish): Verify updating existing entries works
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 2, 2022
1 parent 4dc2e40 commit 6998fb3
Showing 1 changed file with 89 additions and 2 deletions.
91 changes: 89 additions & 2 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 Down Expand Up @@ -2483,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 Down Expand Up @@ -2565,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 <= 1 {
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, 2);
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 6998fb3

Please sign in to comment.