Skip to content

Commit 155906c

Browse files
committed
Make blocking tests non blocking
1 parent 74ad9fa commit 155906c

File tree

8 files changed

+122
-189
lines changed

8 files changed

+122
-189
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ impl HttpServer {
10111011

10121012
pub fn check_authorized_publish(&self, req: &Request) -> Response {
10131013
if let Some(body) = &req.body {
1014+
// Save the body to a file so we can inspect it in the test.
10141015
let path = self.api_path.join("api/v1/crates/new");
10151016
t!(fs::create_dir_all(path.parent().unwrap()));
10161017
t!(fs::write(&path, body));

tests/testsuite/alt_registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn publish_to_alt_registry() {
403403
let _reg = RegistryBuilder::new()
404404
.http_api()
405405
.http_index()
406-
.alternative_named("alternative")
406+
.alternative()
407407
.build();
408408

409409
let p = project().file("src/main.rs", "fn main() {}").build();
@@ -435,7 +435,7 @@ fn publish_with_crates_io_dep() {
435435
let _alt_reg = RegistryBuilder::new()
436436
.http_api()
437437
.http_index()
438-
.alternative_named("alternative")
438+
.alternative()
439439
.build();
440440
let p = project()
441441
.file(

tests/testsuite/artifact_dep.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! the new `dep = { artifact = "bin", … }` syntax in manifests.
33
44
use cargo_test_support::compare::match_exact;
5-
use cargo_test_support::registry::Package;
5+
use cargo_test_support::registry::{Package, RegistryBuilder};
66
use cargo_test_support::{
77
basic_bin_manifest, basic_manifest, cross_compile, project, publish, registry, rustc_host,
88
Project,
@@ -1872,8 +1872,7 @@ fn env_vars_and_build_products_for_various_build_targets() {
18721872

18731873
#[cargo_test]
18741874
fn publish_artifact_dep() {
1875-
// HACK below allows us to use a local registry
1876-
let registry = registry::init();
1875+
let registry = RegistryBuilder::new().http_api().http_index().build();
18771876

18781877
Package::new("bar", "1.0.0").publish();
18791878
Package::new("baz", "1.0.0").publish();
@@ -1903,15 +1902,6 @@ fn publish_artifact_dep() {
19031902
.file("src/lib.rs", "")
19041903
.build();
19051904

1906-
// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
1907-
// the index.
1908-
//
1909-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
1910-
// the registry from processing the publish.
1911-
Package::new("foo", "0.1.0")
1912-
.file("src/lib.rs", "")
1913-
.publish();
1914-
19151905
p.cargo("publish -Z bindeps --no-verify")
19161906
.replace_crates_io(registry.index_url())
19171907
.masquerade_as_nightly_cargo(&["bindeps"])

tests/testsuite/cargo_features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn publish_allowed() {
635635
.masquerade_as_nightly_cargo(&["test-dummy-unstable"])
636636
.with_stderr(
637637
"\
638-
[UPDATING] crates.io index
638+
[UPDATING] [..]
639639
[WARNING] [..]
640640
[..]
641641
[PACKAGING] a v0.0.1 [..]
@@ -644,7 +644,7 @@ fn publish_allowed() {
644644
[FINISHED] [..]
645645
[PACKAGED] [..]
646646
[UPLOADING] a v0.0.1 [..]
647-
[UPDATING] crates.io index
647+
[UPDATING] [..]
648648
",
649649
)
650650
.run();

tests/testsuite/features_namespaced.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for namespaced features.
22
33
use super::features2::switch_to_resolver_2;
4-
use cargo_test_support::registry::{self, Dependency, Package};
4+
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
55
use cargo_test_support::{project, publish};
66

77
#[cargo_test]
@@ -858,8 +858,7 @@ bar v1.0.0
858858

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

864863
// Does not include implicit features or dep: syntax on publish.
865864
Package::new("opt-dep1", "1.0.0").publish();
@@ -887,15 +886,6 @@ fn publish_no_implicit() {
887886
.file("src/lib.rs", "")
888887
.build();
889888

890-
// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
891-
// the index.
892-
//
893-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
894-
// the registry from processing the publish.
895-
Package::new("foo", "0.1.0")
896-
.file("src/lib.rs", "")
897-
.publish();
898-
899889
p.cargo("publish --no-verify")
900890
.replace_crates_io(registry.index_url())
901891
.with_stderr(
@@ -984,8 +974,7 @@ feat = ["opt-dep1"]
984974

985975
#[cargo_test]
986976
fn publish() {
987-
// HACK below allows us to use a local registry
988-
let registry = registry::init();
977+
let registry = RegistryBuilder::new().http_api().http_index().build();
989978

990979
// Publish behavior with explicit dep: syntax.
991980
Package::new("bar", "1.0.0").publish();
@@ -1012,22 +1001,14 @@ fn publish() {
10121001
.file("src/lib.rs", "")
10131002
.build();
10141003

1015-
// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
1016-
// the index.
1017-
//
1018-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
1019-
// the registry from processing the publish.
1020-
Package::new("foo", "0.1.0")
1021-
.file("src/lib.rs", "")
1022-
.publish();
1023-
10241004
p.cargo("publish")
10251005
.replace_crates_io(registry.index_url())
10261006
.with_stderr(
10271007
"\
10281008
[UPDATING] [..]
10291009
[PACKAGING] foo v0.1.0 [..]
10301010
[VERIFYING] foo v0.1.0 [..]
1011+
[UPDATING] [..]
10311012
[COMPILING] foo v0.1.0 [..]
10321013
[FINISHED] [..]
10331014
[PACKAGED] [..]

tests/testsuite/inheritable_workspace_fields.rs

Lines changed: 89 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Tests for inheriting Cargo.toml fields with field.workspace = true
2-
use cargo_test_support::registry::{Dependency, Package};
2+
use cargo_test_support::registry::{Dependency, Package, RegistryBuilder};
33
use cargo_test_support::{
44
basic_lib_manifest, basic_manifest, git, path2url, paths, project, publish, registry,
55
};
@@ -107,7 +107,7 @@ Caused by:
107107

108108
#[cargo_test]
109109
fn inherit_own_workspace_fields() {
110-
let registry = registry::init();
110+
let registry = RegistryBuilder::new().http_api().http_index().build();
111111

112112
let p = project().build();
113113

@@ -160,18 +160,23 @@ fn inherit_own_workspace_fields() {
160160
.file("bar.txt", "") // should be included when packaging
161161
.build();
162162

163-
// HACK: Inject `foo` directly into the index so `publish` won't block for it to be in
164-
// the index.
165-
//
166-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
167-
// the registry from processing the publish.
168-
Package::new("foo", "1.2.3")
169-
.file("src/lib.rs", "")
170-
.publish();
171-
172163
p.cargo("publish")
173164
.replace_crates_io(registry.index_url())
165+
.with_stderr(
166+
"\
167+
[UPDATING] [..]
168+
[WARNING] [..]
169+
[..]
170+
[VERIFYING] foo v1.2.3 [..]
171+
[COMPILING] foo v1.2.3 [..]
172+
[FINISHED] [..]
173+
[PACKAGED] [..]
174+
[UPLOADING] foo v1.2.3 [..]
175+
[UPDATING] [..]
176+
",
177+
)
174178
.run();
179+
175180
publish::validate_upload_with_contents(
176181
r#"
177182
{
@@ -242,7 +247,7 @@ repository = "https://gitlab.com/rust-lang/rust"
242247

243248
#[cargo_test]
244249
fn inherit_own_dependencies() {
245-
let registry = registry::init();
250+
let registry = RegistryBuilder::new().http_api().http_index().build();
246251
let p = project()
247252
.file(
248253
"Cargo.toml",
@@ -297,18 +302,26 @@ fn inherit_own_dependencies() {
297302
assert!(lockfile.contains("dep-dev"));
298303
assert!(lockfile.contains("dep-build"));
299304

300-
// HACK: Inject `bar` directly into the index so `publish` won't block for it to be in
301-
// the index.
302-
//
303-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
304-
// the registry from processing the publish.
305-
Package::new("bar", "0.2.0")
306-
.file("src/lib.rs", "")
307-
.publish();
308-
309305
p.cargo("publish")
310306
.replace_crates_io(registry.index_url())
307+
.with_stderr(
308+
"\
309+
[UPDATING] [..]
310+
[WARNING] [..]
311+
[..]
312+
[PACKAGING] bar v0.2.0 [..]
313+
[UPDATING] [..]
314+
[VERIFYING] bar v0.2.0 [..]
315+
[COMPILING] dep v0.1.2
316+
[COMPILING] bar v0.2.0 [..]
317+
[FINISHED] [..]
318+
[PACKAGED] [..]
319+
[UPLOADING] bar v0.2.0 [..]
320+
[UPDATING] [..]
321+
",
322+
)
311323
.run();
324+
312325
publish::validate_upload_with_contents(
313326
r#"
314327
{
@@ -387,7 +400,7 @@ version = "0.8"
387400

388401
#[cargo_test]
389402
fn inherit_own_detailed_dependencies() {
390-
let registry = registry::init();
403+
let registry = RegistryBuilder::new().http_api().http_index().build();
391404
let p = project()
392405
.file(
393406
"Cargo.toml",
@@ -431,18 +444,26 @@ fn inherit_own_detailed_dependencies() {
431444
let lockfile = p.read_lockfile();
432445
assert!(lockfile.contains("dep"));
433446

434-
// HACK: Inject `bar` directly into the index so `publish` won't block for it to be in
435-
// the index.
436-
//
437-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
438-
// the registry from processing the publish.
439-
Package::new("bar", "0.2.0")
440-
.file("src/lib.rs", "")
441-
.publish();
442-
443447
p.cargo("publish")
444448
.replace_crates_io(registry.index_url())
449+
.with_stderr(
450+
"\
451+
[UPDATING] [..]
452+
[WARNING] [..]
453+
[..]
454+
[PACKAGING] bar v0.2.0 [..]
455+
[UPDATING] [..]
456+
[VERIFYING] bar v0.2.0 [..]
457+
[COMPILING] dep v0.1.2
458+
[COMPILING] bar v0.2.0 [..]
459+
[FINISHED] [..]
460+
[PACKAGED] [..]
461+
[UPLOADING] bar v0.2.0 [..]
462+
[UPDATING] [..]
463+
",
464+
)
445465
.run();
466+
446467
publish::validate_upload_with_contents(
447468
r#"
448469
{
@@ -593,7 +614,7 @@ fn inherited_dependencies_union_features() {
593614

594615
#[cargo_test]
595616
fn inherit_workspace_fields() {
596-
let registry = registry::init();
617+
let registry = RegistryBuilder::new().http_api().http_index().build();
597618

598619
let p = project().build();
599620

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

660-
// HACK: Inject `bar` directly into the index so `publish` won't block for it to be in
661-
// the index.
662-
//
663-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
664-
// the registry from processing the publish.
665-
Package::new("bar", "1.2.3")
666-
.file("src/lib.rs", "")
667-
.publish();
668-
669681
p.cargo("publish")
670682
.replace_crates_io(registry.index_url())
671683
.cwd("bar")
684+
.with_stderr(
685+
"\
686+
[UPDATING] [..]
687+
[WARNING] [..]
688+
[..]
689+
[VERIFYING] bar v1.2.3 [..]
690+
[WARNING] [..]
691+
[..]
692+
[..]
693+
[..]
694+
[COMPILING] bar v1.2.3 [..]
695+
[FINISHED] [..]
696+
[PACKAGED] [..]
697+
[UPLOADING] bar v1.2.3 [..]
698+
[UPDATING] [..]
699+
",
700+
)
672701
.run();
702+
673703
publish::validate_upload_with_contents(
674704
r#"
675705
{
@@ -746,7 +776,7 @@ repository = "https://gitlab.com/rust-lang/rust"
746776

747777
#[cargo_test]
748778
fn inherit_dependencies() {
749-
let registry = registry::init();
779+
let registry = RegistryBuilder::new().http_api().http_index().build();
750780
let p = project()
751781
.file(
752782
"Cargo.toml",
@@ -802,19 +832,27 @@ fn inherit_dependencies() {
802832
assert!(lockfile.contains("dep-dev"));
803833
assert!(lockfile.contains("dep-build"));
804834

805-
// HACK: Inject `bar` directly into the index so `publish` won't block for it to be in
806-
// the index.
807-
//
808-
// This is to ensure we can verify the Summary we post to the registry as doing so precludes
809-
// the registry from processing the publish.
810-
Package::new("bar", "0.2.0")
811-
.file("src/lib.rs", "")
812-
.publish();
813-
814835
p.cargo("publish")
815836
.replace_crates_io(registry.index_url())
816837
.cwd("bar")
838+
.with_stderr(
839+
"\
840+
[UPDATING] [..]
841+
[WARNING] [..]
842+
[..]
843+
[PACKAGING] bar v0.2.0 [..]
844+
[UPDATING] [..]
845+
[VERIFYING] bar v0.2.0 [..]
846+
[COMPILING] dep v0.1.2
847+
[COMPILING] bar v0.2.0 [..]
848+
[FINISHED] [..]
849+
[PACKAGED] [..]
850+
[UPLOADING] bar v0.2.0 [..]
851+
[UPDATING] [..]
852+
",
853+
)
817854
.run();
855+
818856
publish::validate_upload_with_contents(
819857
r#"
820858
{

0 commit comments

Comments
 (0)