@@ -2,12 +2,14 @@ use std::{
22 io:: Write ,
33 path:: { Path , PathBuf } ,
44 process:: Stdio ,
5+ thread:: sleep,
6+ time:: Duration ,
57} ;
68
79use assert_cmd:: Command ;
810use flate2:: bufread:: GzDecoder ;
911use fs_extra:: dir:: CopyOptions ;
10- use predicates:: prelude:: { predicate, PredicateBooleanExt } ;
12+ use predicates:: prelude:: predicate;
1113use tar:: Archive ;
1214
1315#[ test]
@@ -83,48 +85,55 @@ All mimsy were the borogoves,
8385 And the mome raths outgrabe.
8486" ;
8587
86- Command :: new ( "curl" )
87- . current_dir ( & path)
88- . args ( [
89- "-i" ,
90- "-H" ,
91- "content-type: text/plain" ,
92- "--retry-connrefused" ,
93- "--retry" ,
94- "5" ,
95- "--data-binary" ,
96- "@-" ,
97- "http://127.0.0.1:8080/echo" ,
98- ] )
99- . write_stdin ( content)
100- . assert ( )
101- . success ( )
102- . stdout ( predicate:: str:: ends_with ( content) ) ;
103-
104- Command :: new ( "curl" )
105- . current_dir ( & path)
106- . args ( [
107- "-i" ,
108- "-H" ,
109- "url: https://webassembly.github.io/spec/core/" ,
110- "-H" ,
111- "url: https://www.w3.org/groups/wg/wasm/" ,
112- "-H" ,
113- "url: https://bytecodealliance.org/" ,
114- "--retry-connrefused" ,
115- "--retry" ,
116- "5" ,
117- "http://127.0.0.1:8080/hash-all" ,
118- ] )
119- . assert ( )
120- . success ( )
121- . stdout (
122- predicate:: str:: contains ( "https://webassembly.github.io/spec/core/:" ) . and (
123- predicate:: str:: contains ( "https://bytecodealliance.org/:" ) . and (
124- predicate:: str:: contains ( "https://www.w3.org/groups/wg/wasm/:" ) ,
125- ) ,
126- ) ,
127- ) ;
88+ let client = reqwest:: blocking:: Client :: new ( ) ;
89+
90+ fn retry ( func : impl Fn ( ) -> anyhow:: Result < String > ) -> anyhow:: Result < String > {
91+ for i in 0 ..5 {
92+ match func ( ) {
93+ Ok ( text) => {
94+ return Ok ( text) ;
95+ }
96+ Err ( err) => {
97+ if i == 4 {
98+ return Err ( err. into ( ) ) ;
99+ } else {
100+ sleep ( Duration :: from_secs ( 1 ) ) ;
101+ continue ;
102+ }
103+ }
104+ }
105+ }
106+ unreachable ! ( )
107+ }
108+
109+ let echo = || -> anyhow:: Result < String > {
110+ Ok ( client
111+ . post ( "http://127.0.0.1:8080/echo" )
112+ . header ( "content-type" , "text/plain" )
113+ . body ( content)
114+ . send ( ) ?
115+ . error_for_status ( ) ?
116+ . text ( ) ?)
117+ } ;
118+
119+ let text = retry ( echo) ?;
120+ assert ! ( text. ends_with( & content) ) ;
121+
122+ let hash_all = || -> anyhow:: Result < String > {
123+ Ok ( client
124+ . get ( "http://127.0.0.1:8080/hash-all" )
125+ . header ( "url" , "https://webassembly.github.io/spec/core/" )
126+ . header ( "url" , "https://www.w3.org/groups/wg/wasm/" )
127+ . header ( "url" , "https://bytecodealliance.org/" )
128+ . send ( ) ?
129+ . error_for_status ( ) ?
130+ . text ( ) ?)
131+ } ;
132+
133+ let text = retry ( hash_all) ?;
134+ assert ! ( text. contains( "https://webassembly.github.io/spec/core/:" ) ) ;
135+ assert ! ( text. contains( "https://bytecodealliance.org/:" ) ) ;
136+ assert ! ( text. contains( "https://www.w3.org/groups/wg/wasm/:" ) ) ;
128137
129138 handle. kill ( ) ?;
130139
0 commit comments