Skip to content

Commit b0b6b16

Browse files
committed
add test to show existing behavior of block_until_ready
1 parent 8c30ce5 commit b0b6b16

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

src/cargo/sources/registry/http_remote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ impl<'gctx> RegistryData for HttpRegistry<'gctx> {
789789
}
790790

791791
fn block_until_ready(&mut self) -> CargoResult<()> {
792-
trace!(target: "network",
793-
"block_until_ready: {} transfers pending",
792+
trace!(target: "network::HttpRegistry::block_until_ready",
793+
"{} transfers pending",
794794
self.downloads.pending.len()
795795
);
796796
self.downloads.blocking_calls += 1;

tests/testsuite/registry.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,64 @@ Caused by:
33143314
.run();
33153315
}
33163316

3317+
#[cargo_test]
3318+
fn sparse_blocking_count() {
3319+
let fail_count = Mutex::new(0);
3320+
let _registry = RegistryBuilder::new()
3321+
.http_index()
3322+
.add_responder("/index/3/b/bar", move |req, server| {
3323+
let mut fail_count = fail_count.lock().unwrap();
3324+
if *fail_count < 1 {
3325+
*fail_count += 1;
3326+
server.internal_server_error(req)
3327+
} else {
3328+
server.index(req)
3329+
}
3330+
})
3331+
.build();
3332+
3333+
let p = project()
3334+
.file(
3335+
"Cargo.toml",
3336+
r#"
3337+
[package]
3338+
name = "foo"
3339+
version = "0.0.1"
3340+
edition = "2015"
3341+
authors = []
3342+
3343+
[dependencies]
3344+
bar = ">= 0.0.0"
3345+
"#,
3346+
)
3347+
.file("src/main.rs", "fn main() {}")
3348+
.build();
3349+
3350+
Package::new("bar", "0.0.1").publish();
3351+
3352+
p.cargo("check")
3353+
.env("CARGO_LOG", "network::HttpRegistry::block_until_ready=trace")
3354+
.with_stderr_data(str![[r#"
3355+
[..] TRACE network::HttpRegistry::block_until_ready: 0 transfers pending
3356+
[UPDATING] `dummy-registry` index
3357+
[..] TRACE network::HttpRegistry::block_until_ready: 1 transfers pending
3358+
[..] TRACE network::HttpRegistry::block_until_ready: 1 transfers pending
3359+
[..] TRACE network::HttpRegistry::block_until_ready: 1 transfers pending
3360+
[..] TRACE network::HttpRegistry::block_until_ready: 1 transfers pending
3361+
[WARNING] spurious network error (3 tries remaining): failed to get successful HTTP response from `[..]/index/3/b/bar` ([..]), got 500
3362+
body:
3363+
internal server error
3364+
[..] TRACE network::HttpRegistry::block_until_ready: 1 transfers pending
3365+
[LOCKING] 1 package to latest compatible version
3366+
[DOWNLOADING] crates ...
3367+
[DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
3368+
[CHECKING] bar v0.0.1
3369+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3370+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
3371+
3372+
"#]]).run();
3373+
}
3374+
33173375
#[cargo_test]
33183376
fn sparse_retry_single() {
33193377
let fail_count = Mutex::new(0);

0 commit comments

Comments
 (0)