Skip to content

Commit

Permalink
Make blocking tests non blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Feb 23, 2023
1 parent a8233d4 commit 0b06a45
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 189 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 @@ -1011,6 +1011,7 @@ impl HttpServer {

pub fn check_authorized_publish(&self, req: &Request) -> Response {
if let Some(body) = &req.body {
// Save the body to a file so we can inspect it in the test.
let path = self.api_path.join("api/v1/crates/new");
t!(fs::create_dir_all(path.parent().unwrap()));
t!(fs::write(&path, body));
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn publish_to_alt_registry() {
let _reg = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("alternative")
.alternative()
.build();

let p = project().file("src/main.rs", "fn main() {}").build();
Expand Down Expand Up @@ -471,7 +471,7 @@ fn publish_with_crates_io_dep() {
let _alt_reg = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("alternative")
.alternative()
.build();
let p = project()
.file(
Expand Down
14 changes: 2 additions & 12 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! the new `dep = { artifact = "bin", … }` syntax in manifests.

use cargo_test_support::compare::match_exact;
use cargo_test_support::registry::Package;
use cargo_test_support::registry::{Package, RegistryBuilder};
use cargo_test_support::{
basic_bin_manifest, basic_manifest, cross_compile, project, publish, registry, rustc_host,
Project,
Expand Down Expand Up @@ -1872,8 +1872,7 @@ 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();
let registry = RegistryBuilder::new().http_api().http_index().build();

Package::new("bar", "1.0.0").publish();
Package::new("baz", "1.0.0").publish();
Expand Down Expand Up @@ -1903,15 +1902,6 @@ 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
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ fn publish_allowed() {
.masquerade_as_nightly_cargo(&["test-dummy-unstable"])
.with_stderr(
"\
[UPDATING] crates.io index
[UPDATING] [..]
[WARNING] [..]
[..]
[PACKAGING] a v0.0.1 [..]
Expand All @@ -644,7 +644,7 @@ fn publish_allowed() {
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] a v0.0.1 [..]
[UPDATING] crates.io index
[UPDATING] [..]
",
)
.run();
Expand Down
27 changes: 4 additions & 23 deletions tests/testsuite/features_namespaced.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests for namespaced features.

use super::features2::switch_to_resolver_2;
use cargo_test_support::registry::{self, Dependency, Package};
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
use cargo_test_support::{project, publish};

#[cargo_test]
Expand Down Expand Up @@ -858,8 +858,7 @@ bar v1.0.0

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

// Does not include implicit features or dep: syntax on publish.
Package::new("opt-dep1", "1.0.0").publish();
Expand Down Expand Up @@ -887,15 +886,6 @@ 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 @@ -984,8 +974,7 @@ feat = ["opt-dep1"]

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

// Publish behavior with explicit dep: syntax.
Package::new("bar", "1.0.0").publish();
Expand All @@ -1012,22 +1001,14 @@ 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(
"\
[UPDATING] [..]
[PACKAGING] foo v0.1.0 [..]
[VERIFYING] foo v0.1.0 [..]
[UPDATING] [..]
[COMPILING] foo v0.1.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
Expand Down
140 changes: 89 additions & 51 deletions tests/testsuite/inheritable_workspace_fields.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Tests for inheriting Cargo.toml fields with field.workspace = true
use cargo_test_support::registry::{Dependency, Package};
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
use cargo_test_support::{
basic_lib_manifest, basic_manifest, git, path2url, paths, project, publish, registry,
};
Expand Down Expand Up @@ -107,7 +107,7 @@ Caused by:

#[cargo_test]
fn inherit_own_workspace_fields() {
let registry = registry::init();
let registry = RegistryBuilder::new().http_api().http_index().build();

let p = project().build();

Expand Down Expand Up @@ -160,18 +160,23 @@ fn inherit_own_workspace_fields() {
.file("bar.txt", "") // should be included when packaging
.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", "1.2.3")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.with_stderr(
"\
[UPDATING] [..]
[WARNING] [..]
[..]
[VERIFYING] foo v1.2.3 [..]
[COMPILING] foo v1.2.3 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] foo v1.2.3 [..]
[UPDATING] [..]
",
)
.run();

publish::validate_upload_with_contents(
r#"
{
Expand Down Expand Up @@ -242,7 +247,7 @@ repository = "https://gitlab.com/rust-lang/rust"

#[cargo_test]
fn inherit_own_dependencies() {
let registry = registry::init();
let registry = RegistryBuilder::new().http_api().http_index().build();
let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -297,18 +302,26 @@ fn inherit_own_dependencies() {
assert!(lockfile.contains("dep-dev"));
assert!(lockfile.contains("dep-build"));

// HACK: Inject `bar` 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("bar", "0.2.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.with_stderr(
"\
[UPDATING] [..]
[WARNING] [..]
[..]
[PACKAGING] bar v0.2.0 [..]
[UPDATING] [..]
[VERIFYING] bar v0.2.0 [..]
[COMPILING] dep v0.1.2
[COMPILING] bar v0.2.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] bar v0.2.0 [..]
[UPDATING] [..]
",
)
.run();

publish::validate_upload_with_contents(
r#"
{
Expand Down Expand Up @@ -387,7 +400,7 @@ version = "0.8"

#[cargo_test]
fn inherit_own_detailed_dependencies() {
let registry = registry::init();
let registry = RegistryBuilder::new().http_api().http_index().build();
let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -431,18 +444,26 @@ fn inherit_own_detailed_dependencies() {
let lockfile = p.read_lockfile();
assert!(lockfile.contains("dep"));

// HACK: Inject `bar` 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("bar", "0.2.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.with_stderr(
"\
[UPDATING] [..]
[WARNING] [..]
[..]
[PACKAGING] bar v0.2.0 [..]
[UPDATING] [..]
[VERIFYING] bar v0.2.0 [..]
[COMPILING] dep v0.1.2
[COMPILING] bar v0.2.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] bar v0.2.0 [..]
[UPDATING] [..]
",
)
.run();

publish::validate_upload_with_contents(
r#"
{
Expand Down Expand Up @@ -593,7 +614,7 @@ fn inherited_dependencies_union_features() {

#[cargo_test]
fn inherit_workspace_fields() {
let registry = registry::init();
let registry = RegistryBuilder::new().http_api().http_index().build();

let p = project().build();

Expand Down Expand Up @@ -657,19 +678,28 @@ fn inherit_workspace_fields() {
.file("bar/bar.txt", "") // should be included when packaging
.build();

// HACK: Inject `bar` 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("bar", "1.2.3")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.cwd("bar")
.with_stderr(
"\
[UPDATING] [..]
[WARNING] [..]
[..]
[VERIFYING] bar v1.2.3 [..]
[WARNING] [..]
[..]
[..]
[..]
[COMPILING] bar v1.2.3 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] bar v1.2.3 [..]
[UPDATING] [..]
",
)
.run();

publish::validate_upload_with_contents(
r#"
{
Expand Down Expand Up @@ -746,7 +776,7 @@ repository = "https://gitlab.com/rust-lang/rust"

#[cargo_test]
fn inherit_dependencies() {
let registry = registry::init();
let registry = RegistryBuilder::new().http_api().http_index().build();
let p = project()
.file(
"Cargo.toml",
Expand Down Expand Up @@ -802,19 +832,27 @@ fn inherit_dependencies() {
assert!(lockfile.contains("dep-dev"));
assert!(lockfile.contains("dep-build"));

// HACK: Inject `bar` 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("bar", "0.2.0")
.file("src/lib.rs", "")
.publish();

p.cargo("publish")
.replace_crates_io(registry.index_url())
.cwd("bar")
.with_stderr(
"\
[UPDATING] [..]
[WARNING] [..]
[..]
[PACKAGING] bar v0.2.0 [..]
[UPDATING] [..]
[VERIFYING] bar v0.2.0 [..]
[COMPILING] dep v0.1.2
[COMPILING] bar v0.2.0 [..]
[FINISHED] [..]
[PACKAGED] [..]
[UPLOADING] bar v0.2.0 [..]
[UPDATING] [..]
",
)
.run();

publish::validate_upload_with_contents(
r#"
{
Expand Down
Loading

0 comments on commit 0b06a45

Please sign in to comment.