diff --git a/api-gen/tests/return_type_enum.rs b/api-gen/tests/return_type_enum.rs index 6b9faec..f9c42b4 100644 --- a/api-gen/tests/return_type_enum.rs +++ b/api-gen/tests/return_type_enum.rs @@ -1,5 +1,6 @@ use anyhow::Result; use api_gen::QBittorrentApiGen; +use tokio::time::{sleep, Duration}; const USERNAME: &str = "admin"; const PASSWORD: &str = "adminadmin"; @@ -16,9 +17,19 @@ async fn main() -> Result<()> { const TORRENT_URL: &str = "http://www.legittorrents.info/download.php?id=5cc013e801095be61d768e609e3039da58616fd0&f=Oddepoxy%20-%20Oddepoxy%20(2013)%20[OGG%20320%20CBR].torrent"; let _ = api.torrent_management().add(TORRENT_URL).send().await?; - let info = api.torrent_management().info().send().await?; - let first = &info[0]; - assert_ne!(first.state, api_impl::TorrentManagementInfoState::Unknown); + let mut tries = 5; + while tries > 0 { + let info = api.torrent_management().info().send().await?; + if let Some(first) = &info.get(0) { + // just check that something is there + assert_ne!(first.added_on, 0); + return Ok(()); + } else { + tries -= 1; + println!("torrent not found, sleeping for 1 second"); + sleep(Duration::from_secs(1)).await; + } + } - Ok(()) + panic!("Failed to find torrent!"); } diff --git a/api-gen/tests/return_type_with_optional_params.rs b/api-gen/tests/return_type_with_optional_params.rs index 37b7eb2..f9c42b4 100644 --- a/api-gen/tests/return_type_with_optional_params.rs +++ b/api-gen/tests/return_type_with_optional_params.rs @@ -1,5 +1,6 @@ use anyhow::Result; use api_gen::QBittorrentApiGen; +use tokio::time::{sleep, Duration}; const USERNAME: &str = "admin"; const PASSWORD: &str = "adminadmin"; @@ -16,10 +17,19 @@ async fn main() -> Result<()> { const TORRENT_URL: &str = "http://www.legittorrents.info/download.php?id=5cc013e801095be61d768e609e3039da58616fd0&f=Oddepoxy%20-%20Oddepoxy%20(2013)%20[OGG%20320%20CBR].torrent"; let _ = api.torrent_management().add(TORRENT_URL).send().await?; - let info = api.torrent_management().info().send().await?; - let first = &info[0]; - // just check that something is there - assert_ne!(first.added_on, 0); + let mut tries = 5; + while tries > 0 { + let info = api.torrent_management().info().send().await?; + if let Some(first) = &info.get(0) { + // just check that something is there + assert_ne!(first.added_on, 0); + return Ok(()); + } else { + tries -= 1; + println!("torrent not found, sleeping for 1 second"); + sleep(Duration::from_secs(1)).await; + } + } - Ok(()) + panic!("Failed to find torrent!"); }