Skip to content

refactor(tests): Make publish tests work with wait-for-publish #11217

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

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 11 additions & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,9 @@ fn env_vars_and_build_products_for_various_build_targets() {

#[cargo_test]
fn publish_artifact_dep() {
// HACK below allows us to use a local registry
let registry = registry::init();

Package::new("bar", "1.0.0").publish();
Package::new("baz", "1.0.0").publish();

Expand Down Expand Up @@ -1901,6 +1903,15 @@ fn publish_artifact_dep() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish -Z bindeps --no-verify")
.replace_crates_io(registry.index_url())
.masquerade_as_nightly_cargo(&["bindeps"])
Expand Down
12 changes: 11 additions & 1 deletion tests/testsuite/credential_process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests for credential-process.

use cargo_test_support::registry::TestRegistry;
use cargo_test_support::registry::{Package, TestRegistry};
use cargo_test_support::{basic_manifest, cargo_process, paths, project, registry, Project};
use std::fs;

Expand Down Expand Up @@ -94,6 +94,16 @@ fn warn_both_token_and_process() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about disabling the blocking for these tests instead? Can we set publish.timeout = 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if we had a --no-wait option to cargo publish that could be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for calling that out; I had forgotten to include it in my list.

I had considered it but it would require "nightly" until #11222 is stablized and was wanting to keep the tests focused on "stable" for now.

I had also considered making the default be determined by the source so a local registry could always specify 0 but that was going to require plumbing a fairly specific use case through several traits and I was hesitant on whether that was worth it.

// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.alternative(true)
.publish();

p.cargo("publish --no-verify --registry alternative -Z credential-process")
.masquerade_as_nightly_cargo(&["credential-process"])
.with_status(101)
Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/cross_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn publish_with_target() {
return;
}

let registry = registry::init();
// `publish` generally requires a remote registry
let registry = registry::RegistryBuilder::new().http_api().build();

let p = project()
.file(
Expand Down
22 changes: 22 additions & 0 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,9 @@ bar v1.0.0

#[cargo_test]
fn publish_no_implicit() {
// HACK below allows us to use a local registry
let registry = registry::init();

// Does not include implicit features or dep: syntax on publish.
Package::new("opt-dep1", "1.0.0").publish();
Package::new("opt-dep2", "1.0.0").publish();
Expand All @@ -885,6 +887,15 @@ fn publish_no_implicit() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish --no-verify")
.replace_crates_io(registry.index_url())
.with_stderr(
Expand Down Expand Up @@ -971,7 +982,9 @@ feat = ["opt-dep1"]

#[cargo_test]
fn publish() {
// HACK below allows us to use a local registry
let registry = registry::init();

// Publish behavior with explicit dep: syntax.
Package::new("bar", "1.0.0").publish();
let p = project()
Expand All @@ -997,6 +1010,15 @@ fn publish() {
.file("src/lib.rs", "")
.build();

// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
// the index.
//
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
// the registry from processing the publish.
Package::new("foo", "0.1.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.with_stderr(
Expand Down
Loading