@@ -2398,7 +2398,7 @@ fn http_api_not_noop() {
23982398}
23992399
24002400#[ cargo_test]
2401- fn wait_for_publish ( ) {
2401+ fn wait_for_first_publish ( ) {
24022402 // Counter for number of tries before the package is "published"
24032403 let arc: Arc < Mutex < u32 > > = Arc :: new ( Mutex :: new ( 0 ) ) ;
24042404 let arc2 = arc. clone ( ) ;
@@ -2419,12 +2419,6 @@ fn wait_for_publish() {
24192419 } )
24202420 . build ( ) ;
24212421
2422- // The sparse-registry test server does not know how to publish on its own.
2423- // So let us call publish for it.
2424- Package :: new ( "delay" , "0.0.1" )
2425- . file ( "src/lib.rs" , "" )
2426- . publish ( ) ;
2427-
24282422 let p = project ( )
24292423 . file (
24302424 "Cargo.toml" ,
@@ -2489,7 +2483,7 @@ See [..]
24892483/// the responder twice per cargo invocation. If that ever gets changed
24902484/// this test will need to be changed accordingly.
24912485#[ cargo_test]
2492- fn wait_for_publish_underscore ( ) {
2486+ fn wait_for_first_publish_underscore ( ) {
24932487 // Counter for number of tries before the package is "published"
24942488 let arc: Arc < Mutex < u32 > > = Arc :: new ( Mutex :: new ( 0 ) ) ;
24952489 let arc2 = arc. clone ( ) ;
@@ -2510,12 +2504,6 @@ fn wait_for_publish_underscore() {
25102504 } )
25112505 . build ( ) ;
25122506
2513- // The sparse-registry test server does not know how to publish on its own.
2514- // So let us call publish for it.
2515- Package :: new ( "delay_with_underscore" , "0.0.1" )
2516- . file ( "src/lib.rs" , "" )
2517- . publish ( ) ;
2518-
25192507 let p = project ( )
25202508 . file (
25212509 "Cargo.toml" ,
@@ -2577,6 +2565,93 @@ See [..]
25772565 . run ( ) ;
25782566}
25792567
2568+ #[ cargo_test]
2569+ fn wait_for_subsequent_publish ( ) {
2570+ // Counter for number of tries before the package is "published"
2571+ let arc: Arc < Mutex < u32 > > = Arc :: new ( Mutex :: new ( 0 ) ) ;
2572+ let arc2 = arc. clone ( ) ;
2573+
2574+ // Registry returns an invalid response.
2575+ let registry = registry:: RegistryBuilder :: new ( )
2576+ . http_index ( )
2577+ . http_api ( )
2578+ . add_responder ( "/index/de/la/delay" , move |req, server| {
2579+ let mut lock = arc. lock ( ) . unwrap ( ) ;
2580+ * lock += 1 ;
2581+ // if the package name contains _ or -
2582+ if * lock <= 2 {
2583+ server. not_found ( req)
2584+ } else {
2585+ server. index ( req)
2586+ }
2587+ } )
2588+ . build ( ) ;
2589+
2590+ // Publish an earlier version
2591+ Package :: new ( "delay" , "0.0.1" )
2592+ . file ( "src/lib.rs" , "" )
2593+ . publish ( ) ;
2594+
2595+ let p = project ( )
2596+ . file (
2597+ "Cargo.toml" ,
2598+ r#"
2599+ [package]
2600+ name = "delay"
2601+ version = "0.0.2"
2602+ authors = []
2603+ license = "MIT"
2604+ description = "foo"
2605+
2606+ "# ,
2607+ )
2608+ . file ( "src/lib.rs" , "" )
2609+ . build ( ) ;
2610+
2611+ p. cargo ( "publish --no-verify -Z sparse-registry" )
2612+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2613+ . replace_crates_io ( registry. index_url ( ) )
2614+ . with_status ( 0 )
2615+ . with_stderr (
2616+ "\
2617+ [UPDATING] crates.io index
2618+ [WARNING] manifest has no documentation, [..]
2619+ See [..]
2620+ [PACKAGING] delay v0.0.2 ([CWD])
2621+ [PACKAGED] [..] files, [..] ([..] compressed)
2622+ [UPLOADING] delay v0.0.2 ([CWD])
2623+ [UPDATING] crates.io index
2624+ [WAITING] on `delay` to propagate to crates.io index (ctrl-c to wait asynchronously)
2625+ " ,
2626+ )
2627+ . run ( ) ;
2628+
2629+ // Verify the responder has been pinged
2630+ let lock = arc2. lock ( ) . unwrap ( ) ;
2631+ assert_eq ! ( * lock, 3 ) ;
2632+ drop ( lock) ;
2633+
2634+ let p = project ( )
2635+ . file (
2636+ "Cargo.toml" ,
2637+ r#"
2638+ [package]
2639+ name = "foo"
2640+ version = "0.0.1"
2641+ authors = []
2642+ [dependencies]
2643+ delay = "0.0.2"
2644+ "# ,
2645+ )
2646+ . file ( "src/main.rs" , "fn main() {}" )
2647+ . build ( ) ;
2648+
2649+ p. cargo ( "build -Z sparse-registry" )
2650+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2651+ . with_status ( 0 )
2652+ . run ( ) ;
2653+ }
2654+
25802655#[ cargo_test]
25812656fn skip_wait_for_publish ( ) {
25822657 // Intentionally using local registry so the crate never makes it to the index
0 commit comments