// License: see LICENSE file at root directory of `master` branch use std::{ env, path::PathBuf, str::FromStr, sync::mpsc::TrySendError, time::{Duration, Instant}, }; use ice_age::{Config, Cmd, Log}; /// # Gets test duration fn test_duration() -> Duration { Duration::from_secs(match env::var("TEST_DURATION").map(|s| u8::from_str(&s).map(|d| d.max(1) as u64)) { Ok(Ok(duration)) => duration, _ => 10, }) } #[test] fn sending() { let config = Config { work_dir: PathBuf::from(file!()).parent().unwrap().to_path_buf(), max_file_len: 30 * 1024 * 1024, log_files_reserved: Duration::from_secs(10), buf_len: 50000, disk_flush_interval: Duration::from_secs(3), }; let test_duration = test_duration(); let start_time = Instant::now(); let logger = ice_age::Logger::make(config).unwrap(); loop { let log = Log { time: 1, remote_ip: "localhost:9191".repeat(10), url: "localhost::9191".repeat(10), response_size: None, code: 0, runtime: Duration::from_secs(1), notes: Some(String::from("Test")), }; match logger.try_send(Cmd::StoreLog(log)) { Ok(()) => (), Err(TrySendError::Full(_)) => (), Err(TrySendError::Disconnected(_)) => { eprintln!("Failed to send log: server disconnected"); break; }, } if Instant::now().duration_since(start_time) >= test_duration { break; } } }