Add timeout to test

This commit is contained in:
johannesd3 2021-04-14 19:32:15 +02:00
parent 79f75b9119
commit 68818758a2
No known key found for this signature in database
GPG key ID: 8C2739E91D410F75

View file

@ -1,9 +1,14 @@
use std::time::Duration;
use librespot_core::authentication::Credentials; use librespot_core::authentication::Credentials;
use librespot_core::config::SessionConfig; use librespot_core::config::SessionConfig;
use librespot_core::session::Session; use librespot_core::session::Session;
use tokio::time::timeout;
#[tokio::test] #[tokio::test]
async fn test_connection() { async fn test_connection() {
timeout(Duration::from_secs(30), async {
let result = Session::connect( let result = Session::connect(
SessionConfig::default(), SessionConfig::default(),
Credentials::with_password("test", "test"), Credentials::with_password("test", "test"),
@ -14,5 +19,8 @@ async fn test_connection() {
match result { match result {
Ok(_) => panic!("Authentication succeeded despite of bad credentials."), Ok(_) => panic!("Authentication succeeded despite of bad credentials."),
Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"), Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"),
}; }
})
.await
.unwrap();
} }