@@ -79,9 +79,6 @@ fn http_example() -> anyhow::Result<()> {
7979 . args ( [ "serve" , "--wasi" , "common" , "http.wasm" ] )
8080 . spawn ( ) ?;
8181
82- // Sleep a bit to give the server time to start
83- std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
84-
8582 let content = "’Twas brillig, and the slithy toves
8683 Did gyre and gimble in the wabe:
8784All mimsy were the borogoves,
@@ -90,20 +87,18 @@ All mimsy were the borogoves,
9087
9188 let client = reqwest:: blocking:: Client :: new ( ) ;
9289
93- let echo = || -> anyhow :: Result < String > {
90+ let text = retry ( || {
9491 Ok ( client
9592 . post ( "http://127.0.0.1:8080/echo" )
9693 . header ( "content-type" , "text/plain" )
9794 . body ( content)
9895 . send ( ) ?
9996 . error_for_status ( ) ?
10097 . text ( ) ?)
101- } ;
102-
103- let text = retry ( echo, 5 ) ?;
98+ } ) ?;
10499 assert ! ( text. ends_with( & content) ) ;
105100
106- let hash_all = || -> anyhow :: Result < String > {
101+ let text = retry ( || {
107102 Ok ( client
108103 . get ( "http://127.0.0.1:8080/hash-all" )
109104 . header ( "url" , "https://webassembly.github.io/spec/core/" )
@@ -112,9 +107,7 @@ All mimsy were the borogoves,
112107 . send ( ) ?
113108 . error_for_status ( ) ?
114109 . text ( ) ?)
115- } ;
116-
117- let text = retry ( hash_all, 5 ) ?;
110+ } ) ?;
118111 assert ! ( text. contains( "https://webassembly.github.io/spec/core/:" ) ) ;
119112 assert ! ( text. contains( "https://bytecodealliance.org/:" ) ) ;
120113 assert ! ( text. contains( "https://www.w3.org/groups/wg/wasm/:" ) ) ;
@@ -275,7 +268,8 @@ fn tcp_example() -> anyhow::Result<()> {
275268 Ok ( ( ) )
276269}
277270
278- fn retry < T > ( mut func : impl FnMut ( ) -> anyhow:: Result < T > , times : usize ) -> anyhow:: Result < T > {
271+ fn retry < T > ( mut func : impl FnMut ( ) -> anyhow:: Result < T > ) -> anyhow:: Result < T > {
272+ let times = 8 ;
279273 for i in 0 ..times {
280274 match func ( ) {
281275 Ok ( t) => {
@@ -285,7 +279,7 @@ fn retry<T>(mut func: impl FnMut() -> anyhow::Result<T>, times: usize) -> anyhow
285279 if i == times - 1 {
286280 return Err ( err) ;
287281 } else {
288- sleep ( Duration :: from_secs ( i as u64 + 1 ) ) ;
282+ sleep ( Duration :: from_millis ( 2_u64 . pow ( i ) * 100 ) ) ;
289283 continue ;
290284 }
291285 }
0 commit comments