diff --git a/src/db.rs b/src/db.rs index d204396..b879256 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1151,7 +1151,7 @@ mod tests { #[test] fn test_adjust_days() { - testutil::init_logging(); + testutil::init(); let mut m = BTreeMap::new(); // Create a day. @@ -1206,7 +1206,7 @@ mod tests { /// Basic test of running some queries on an empty database. #[test] fn test_empty_db() { - testutil::init_logging(); + testutil::init(); let conn = setup_conn(); let db = Database::new(conn).unwrap(); let db = db.lock(); @@ -1216,7 +1216,7 @@ mod tests { /// Basic test of the full lifecycle of recording. Does not exercise error cases. #[test] fn test_full_lifecycle() { - testutil::init_logging(); + testutil::init(); let conn = setup_conn(); let camera_uuid = Uuid::new_v4(); let camera_id = setup_camera(&conn, camera_uuid, "testcam"); @@ -1289,7 +1289,7 @@ mod tests { #[test] fn test_drop_tx() { - testutil::init_logging(); + testutil::init(); let conn = setup_conn(); let db = Database::new(conn).unwrap(); let mut db = db.lock(); diff --git a/src/mp4.rs b/src/mp4.rs index 35d12c6..014e0db 100644 --- a/src/mp4.rs +++ b/src/mp4.rs @@ -1342,7 +1342,7 @@ mod tests { #[test] fn test_round_trip() { - testutil::init_logging(); + testutil::init(); let db = setup_db(); copy_mp4_to_db(&db); let mp4 = create_mp4_from_db(db.db.clone(), db.dir.clone(), 0, 0, false); @@ -1362,7 +1362,7 @@ mod tests { #[test] fn test_round_trip_with_subtitles() { - testutil::init_logging(); + testutil::init(); let db = setup_db(); copy_mp4_to_db(&db); let mp4 = create_mp4_from_db(db.db.clone(), db.dir.clone(), 0, 0, true); @@ -1382,7 +1382,7 @@ mod tests { #[test] fn test_round_trip_with_edit_list() { - testutil::init_logging(); + testutil::init(); let db = setup_db(); copy_mp4_to_db(&db); let mp4 = create_mp4_from_db(db.db.clone(), db.dir.clone(), 1, 0, false); @@ -1402,7 +1402,7 @@ mod tests { #[test] fn test_round_trip_with_shorten() { - testutil::init_logging(); + testutil::init(); let db = setup_db(); copy_mp4_to_db(&db); let mp4 = create_mp4_from_db(db.db.clone(), db.dir.clone(), 0, 1, false); @@ -1478,7 +1478,7 @@ mod tests { /// Benchmarks serving the generated part of a `.mp4` file (up to the first byte from disk). #[bench] fn serve_generated_bytes_fresh_client(b: &mut Bencher) { - testutil::init_logging(); + testutil::init(); let server = &*SERVER; let p = server.generated_len; let mut buf = Vec::with_capacity(p as usize); @@ -1503,7 +1503,7 @@ mod tests { /// algorithm. #[bench] fn serve_generated_bytes_reuse_client(b: &mut Bencher) { - testutil::init_logging(); + testutil::init(); let server = &*SERVER; let p = server.generated_len; let mut buf = Vec::with_capacity(p as usize); @@ -1524,7 +1524,7 @@ mod tests { #[bench] fn mp4_construction(b: &mut Bencher) { - testutil::init_logging(); + testutil::init(); let db = setup_db(); add_dummy_recordings_to_db(&db.db); b.iter(|| { diff --git a/src/resource.rs b/src/resource.rs index 972b8a5..358ac53 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -418,7 +418,7 @@ mod tests { #[test] fn serve_without_etag() { - testutil::init_logging(); + testutil::init(); *RESOURCE.lock().unwrap() = Some(FakeResource{ etag: None, mime: mime!(Application/OctetStream), @@ -561,7 +561,7 @@ mod tests { #[test] fn serve_with_strong_etag() { - testutil::init_logging(); + testutil::init(); *RESOURCE.lock().unwrap() = Some(FakeResource{ etag: Some(EntityTag::strong("foo".to_owned())), mime: mime!(Application/OctetStream), @@ -630,7 +630,7 @@ mod tests { #[test] fn serve_with_weak_etag() { - testutil::init_logging(); + testutil::init(); *RESOURCE.lock().unwrap() = Some(FakeResource{ etag: Some(EntityTag::weak("foo".to_owned())), mime: mime!(Application/OctetStream), diff --git a/src/testutil.rs b/src/testutil.rs index ea0b65d..07f53cd 100644 --- a/src/testutil.rs +++ b/src/testutil.rs @@ -28,18 +28,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::env; use std::sync; use slog::{self, DrainExt}; use slog_envlogger; use slog_stdlog; use slog_term; +use time; -static INIT_LOGGING: sync::Once = sync::ONCE_INIT; +static INIT: sync::Once = sync::ONCE_INIT; -pub fn init_logging() { - INIT_LOGGING.call_once(|| { +/// Performs global initialization for tests. +/// * set up logging. (Note the output can be confusing unless `RUST_TEST_THREADS=1` is set in +/// the program's environment prior to running.) +/// * set `TZ=America/Los_Angeles` so that tests that care about calendar time get the expected +/// results regardless of machine setup.) +pub fn init() { + INIT.call_once(|| { let drain = slog_term::StreamerBuilder::new().async().full().build(); let drain = slog_envlogger::new(drain); slog_stdlog::set_logger(slog::Logger::root(drain.ignore_err(), None)).unwrap(); + env::set_var("TZ", "America/Los_Angeles"); + time::tzset(); }); }