@@ -2049,3 +2049,215 @@ error: package ID specification `bar` did not match any packages
20492049 )
20502050 . run ( ) ;
20512051}
2052+
2053+ #[ cargo_test]
2054+ fn delayed_publish_errors ( ) {
2055+ // Counter for number of tries before the package is "published"
2056+ let arc: Arc < Mutex < u32 > > = Arc :: new ( Mutex :: new ( 0 ) ) ;
2057+ let arc2 = arc. clone ( ) ;
2058+
2059+ // Registry returns an invalid response.
2060+ let _registry = registry:: RegistryBuilder :: new ( )
2061+ . http_index ( )
2062+ . http_api ( )
2063+ . add_responder ( "/index/de/la/delay" , move |req, server| {
2064+ let mut lock = arc. lock ( ) . unwrap ( ) ;
2065+ * lock += 1 ;
2066+ // if the package name contains _ or
2067+ if * lock <= 1 {
2068+ server. not_found ( req)
2069+ } else {
2070+ server. index ( req)
2071+ }
2072+ } )
2073+ . build ( ) ;
2074+
2075+ // The sparse-registry test server does not know how to publish on its own.
2076+ // So let us call publish for it.
2077+ Package :: new ( "delay" , "0.0.1" )
2078+ . file ( "src/lib.rs" , "" )
2079+ . publish ( ) ;
2080+
2081+ let p = project ( )
2082+ . file (
2083+ "Cargo.toml" ,
2084+ r#"
2085+ [project]
2086+ name = "delay"
2087+ version = "0.0.1"
2088+ authors = []
2089+ license = "MIT"
2090+ description = "foo"
2091+
2092+ "# ,
2093+ )
2094+ . file ( "src/lib.rs" , "" )
2095+ . build ( ) ;
2096+
2097+ p. cargo ( "publish --no-verify -Z sparse-registry" )
2098+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2099+ . with_status ( 0 )
2100+ . with_stderr (
2101+ "\
2102+ [UPDATING] `dummy-registry` index
2103+ [WARNING] using `registry.token` config value with source replacement is deprecated
2104+ This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/xxx>.
2105+ Use the --token command-line flag to remove this warning.
2106+ [WARNING] manifest has no documentation, [..]
2107+ See [..]
2108+ [PACKAGING] delay v0.0.1 ([CWD])
2109+ [UPLOADING] delay v0.0.1 ([CWD])
2110+ " ,
2111+ )
2112+ . run ( ) ;
2113+
2114+ // Check nothing has touched the responder
2115+ let lock = arc2. lock ( ) . unwrap ( ) ;
2116+ assert_eq ! ( * lock, 0 ) ;
2117+ drop ( lock) ;
2118+
2119+ let p = project ( )
2120+ . file (
2121+ "Cargo.toml" ,
2122+ r#"
2123+ [project]
2124+ name = "foo"
2125+ version = "0.0.1"
2126+ authors = []
2127+ [dependencies]
2128+ delay = "0.0.1"
2129+ "# ,
2130+ )
2131+ . file ( "src/main.rs" , "fn main() {}" )
2132+ . build ( ) ;
2133+
2134+ p. cargo ( "build -Z sparse-registry" )
2135+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2136+ . with_status ( 101 )
2137+ . with_stderr (
2138+ "\
2139+ [UPDATING] [..]
2140+ [ERROR] no matching package named `delay` found
2141+ location searched: registry `crates-io`
2142+ required by package `foo v0.0.1 ([..]/foo)`
2143+ " ,
2144+ )
2145+ . run ( ) ;
2146+
2147+ let lock = arc2. lock ( ) . unwrap ( ) ;
2148+ assert_eq ! ( * lock, 1 ) ;
2149+ drop ( lock) ;
2150+
2151+ p. cargo ( "build -Z sparse-registry" )
2152+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2153+ . with_status ( 0 )
2154+ . run ( ) ;
2155+ }
2156+
2157+ /// A separate test is needed for package names with - or _ as they hit
2158+ /// the responder twice per cargo invocation. If that ever gets changed
2159+ /// this test will need to be changed accordingly.
2160+ #[ cargo_test]
2161+ fn delayed_publish_errors_underscore ( ) {
2162+ // Counter for number of tries before the package is "published"
2163+ let arc: Arc < Mutex < u32 > > = Arc :: new ( Mutex :: new ( 0 ) ) ;
2164+ let arc2 = arc. clone ( ) ;
2165+
2166+ // Registry returns an invalid response.
2167+ let _registry = registry:: RegistryBuilder :: new ( )
2168+ . http_index ( )
2169+ . http_api ( )
2170+ . add_responder ( "/index/de/la/delay_with_underscore" , move |req, server| {
2171+ let mut lock = arc. lock ( ) . unwrap ( ) ;
2172+ * lock += 1 ;
2173+ // package names with - or _ hit the responder twice per cargo invocation
2174+ if * lock <= 2 {
2175+ server. not_found ( req)
2176+ } else {
2177+ server. index ( req)
2178+ }
2179+ } )
2180+ . build ( ) ;
2181+
2182+ // The sparse-registry test server does not know how to publish on its own.
2183+ // So let us call publish for it.
2184+ Package :: new ( "delay_with_underscore" , "0.0.1" )
2185+ . file ( "src/lib.rs" , "" )
2186+ . publish ( ) ;
2187+
2188+ let p = project ( )
2189+ . file (
2190+ "Cargo.toml" ,
2191+ r#"
2192+ [project]
2193+ name = "delay_with_underscore"
2194+ version = "0.0.1"
2195+ authors = []
2196+ license = "MIT"
2197+ description = "foo"
2198+
2199+ "# ,
2200+ )
2201+ . file ( "src/lib.rs" , "" )
2202+ . build ( ) ;
2203+
2204+ p. cargo ( "publish --no-verify -Z sparse-registry" )
2205+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2206+ . with_status ( 0 )
2207+ . with_stderr (
2208+ "\
2209+ [UPDATING] `dummy-registry` index
2210+ [WARNING] using `registry.token` config value with source replacement is deprecated
2211+ This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/xxx>.
2212+ Use the --token command-line flag to remove this warning.
2213+ [WARNING] manifest has no documentation, [..]
2214+ See [..]
2215+ [PACKAGING] delay_with_underscore v0.0.1 ([CWD])
2216+ [UPLOADING] delay_with_underscore v0.0.1 ([CWD])
2217+ " ,
2218+ )
2219+ . run ( ) ;
2220+
2221+ // Check nothing has touched the responder
2222+ let lock = arc2. lock ( ) . unwrap ( ) ;
2223+ assert_eq ! ( * lock, 0 ) ;
2224+ drop ( lock) ;
2225+
2226+ let p = project ( )
2227+ . file (
2228+ "Cargo.toml" ,
2229+ r#"
2230+ [project]
2231+ name = "foo"
2232+ version = "0.0.1"
2233+ authors = []
2234+ [dependencies]
2235+ delay_with_underscore = "0.0.1"
2236+ "# ,
2237+ )
2238+ . file ( "src/main.rs" , "fn main() {}" )
2239+ . build ( ) ;
2240+
2241+ p. cargo ( "build -Z sparse-registry" )
2242+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2243+ . with_status ( 101 )
2244+ . with_stderr (
2245+ "\
2246+ [UPDATING] [..]
2247+ [ERROR] no matching package named `delay_with_underscore` found
2248+ location searched: registry `crates-io`
2249+ required by package `foo v0.0.1 ([..]/foo)`
2250+ " ,
2251+ )
2252+ . run ( ) ;
2253+
2254+ let lock = arc2. lock ( ) . unwrap ( ) ;
2255+ // package names with - or _ hit the responder twice per cargo invocation
2256+ assert_eq ! ( * lock, 2 ) ;
2257+ drop ( lock) ;
2258+
2259+ p. cargo ( "build -Z sparse-registry" )
2260+ . masquerade_as_nightly_cargo ( & [ "sparse-registry" ] )
2261+ . with_status ( 0 )
2262+ . run ( ) ;
2263+ }
0 commit comments