From 68818758a217d078baabe9d854b65b40527a64f0 Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Wed, 14 Apr 2021 19:32:15 +0200 Subject: [PATCH] Add timeout to test --- core/tests/connect.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/tests/connect.rs b/core/tests/connect.rs index 4f1dbe6b..8b95e437 100644 --- a/core/tests/connect.rs +++ b/core/tests/connect.rs @@ -1,18 +1,26 @@ +use std::time::Duration; + use librespot_core::authentication::Credentials; use librespot_core::config::SessionConfig; use librespot_core::session::Session; +use tokio::time::timeout; + #[tokio::test] async fn test_connection() { - let result = Session::connect( - SessionConfig::default(), - Credentials::with_password("test", "test"), - None, - ) - .await; + timeout(Duration::from_secs(30), async { + let result = Session::connect( + SessionConfig::default(), + Credentials::with_password("test", "test"), + None, + ) + .await; - match result { - Ok(_) => panic!("Authentication succeeded despite of bad credentials."), - Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"), - }; + match result { + Ok(_) => panic!("Authentication succeeded despite of bad credentials."), + Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"), + } + }) + .await + .unwrap(); }