diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-10-06 21:03:30 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-06 15:03:30 -0400 |
commit | e1d49fe0fec2f0573f38d24c47c128b78cb43498 (patch) | |
tree | d5bbc5338919145e76c3031854b9d8b951f10901 /cli/http_util.rs | |
parent | 3e02d7ddbc04cf3bfc681a5f4cfe6b91a9860cbd (diff) |
remove more calls to tokio_util::block_on (#3059)
towards #2960
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r-- | cli/http_util.rs | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index abeeffb7a..754cd60d2 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -139,22 +139,22 @@ mod tests { use super::*; use crate::tokio_util; - pub fn fetch_string_once_sync(url: &Url) -> Result<FetchOnceResult, ErrBox> { - tokio_util::block_on(fetch_string_once(url)) - } - #[test] fn test_fetch_sync_string() { let http_server_guard = crate::test_util::http_server(); // Relies on external http server. See tools/http_server.py let url = Url::parse("http://127.0.0.1:4545/package.json").unwrap(); - tokio_util::init(|| match fetch_string_once_sync(&url).unwrap() { - FetchOnceResult::Code(code, maybe_content_type) => { + + let fut = fetch_string_once(&url).then(|result| match result { + Ok(FetchOnceResult::Code(code, maybe_content_type)) => { assert!(!code.is_empty()); assert_eq!(maybe_content_type, Some("application/json".to_string())); + Ok(()) } - _ => unreachable!(), + _ => panic!(), }); + + tokio_util::run(fut); drop(http_server_guard); } @@ -165,10 +165,15 @@ mod tests { let url = Url::parse("http://127.0.0.1:4546/package.json").unwrap(); // Dns resolver substitutes `127.0.0.1` with `localhost` let target_url = Url::parse("http://localhost:4545/package.json").unwrap(); - tokio_util::init(|| { - let result = fetch_string_once_sync(&url).unwrap(); - assert_eq!(result, FetchOnceResult::Redirect(target_url)); + let fut = fetch_string_once(&url).then(move |result| match result { + Ok(FetchOnceResult::Redirect(url)) => { + assert_eq!(url, target_url); + Ok(()) + } + _ => panic!(), }); + + tokio_util::run(fut); drop(http_server_guard); } |