From d9f65e3242832f03ed48550750147d825feaf73b Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Thu, 28 Jul 2022 10:38:43 -0400 Subject: [PATCH 1/2] Quiet sled agent tests --- sled-agent/src/instance.rs | 14 +++++--------- sled-agent/src/instance_manager.rs | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/sled-agent/src/instance.rs b/sled-agent/src/instance.rs index 15a8672666..9e59923b46 100644 --- a/sled-agent/src/instance.rs +++ b/sled-agent/src/instance.rs @@ -807,6 +807,7 @@ mod test { ByteCount, Generation, InstanceCpuCount, InstanceState, }; use omicron_common::api::internal::nexus::InstanceRuntimeState; + use omicron_test_utils::dev::test_setup_log; use std::net::IpAddr; use std::net::Ipv4Addr; @@ -821,14 +822,6 @@ mod test { PROPOLIS_UUID_STR.parse().unwrap() } - fn logger() -> Logger { - dropshot::ConfigLogging::StderrTerminal { - level: dropshot::ConfigLoggingLevel::Info, - } - .to_logger("test-logger") - .unwrap() - } - fn new_initial_instance() -> InstanceHardware { InstanceHardware { runtime: InstanceRuntimeState { @@ -874,7 +867,8 @@ mod test { expected = "Propolis client should be initialized before usage" )] async fn transition_before_start() { - let log = logger(); + let logctx = test_setup_log("transition_before_start"); + let log = &logctx.log; let vnic_allocator = VnicAllocator::new( "Test".to_string(), Etherstub("mylink".to_string()), @@ -907,5 +901,7 @@ mod test { }) .await .unwrap(); + + logctx.cleanup_successful(); } } diff --git a/sled-agent/src/instance_manager.rs b/sled-agent/src/instance_manager.rs index 6284dc0acc..a0ef879bed 100644 --- a/sled-agent/src/instance_manager.rs +++ b/sled-agent/src/instance_manager.rs @@ -238,6 +238,7 @@ mod test { ByteCount, Generation, InstanceCpuCount, InstanceState, }; use omicron_common::api::internal::nexus::InstanceRuntimeState; + use omicron_test_utils::dev::test_setup_log; use std::net::IpAddr; use std::net::Ipv4Addr; @@ -247,14 +248,6 @@ mod test { INST_UUID_STR.parse().unwrap() } - fn logger() -> Logger { - dropshot::ConfigLogging::StderrTerminal { - level: dropshot::ConfigLoggingLevel::Info, - } - .to_logger("test-logger") - .unwrap() - } - fn new_initial_instance() -> InstanceHardware { InstanceHardware { runtime: InstanceRuntimeState { @@ -285,7 +278,8 @@ mod test { #[tokio::test] #[serial_test::serial] async fn ensure_instance() { - let log = logger(); + let logctx = test_setup_log("ensure_instance"); + let log = &logctx.log; let lazy_nexus_client = LazyNexusClient::new(log.clone(), std::net::Ipv6Addr::LOCALHOST) .unwrap(); @@ -300,7 +294,7 @@ mod test { dladm_get_vnics_ctx.expect().return_once(|| Ok(vec![])); let im = InstanceManager::new( - log, + log.clone(), lazy_nexus_client, Etherstub("mylink".to_string()), std::net::Ipv6Addr::new( @@ -366,12 +360,15 @@ mod test { // the entry is automatically removed from the instance manager. ticket.lock().unwrap().take(); assert_eq!(im.inner.instances.lock().unwrap().len(), 0); + + logctx.cleanup_successful(); } #[tokio::test] #[serial_test::serial] async fn ensure_instance_repeatedly() { - let log = logger(); + let logctx = test_setup_log("ensure_instance_repeatedly"); + let log = &logctx.log; let lazy_nexus_client = LazyNexusClient::new(log.clone(), std::net::Ipv6Addr::LOCALHOST) .unwrap(); @@ -385,7 +382,7 @@ mod test { dladm_get_vnics_ctx.expect().return_once(|| Ok(vec![])); let im = InstanceManager::new( - log, + log.clone(), lazy_nexus_client, Etherstub("mylink".to_string()), std::net::Ipv6Addr::new( @@ -449,5 +446,7 @@ mod test { assert_eq!(im.inner.instances.lock().unwrap().len(), 1); ticket.lock().unwrap().take(); assert_eq!(im.inner.instances.lock().unwrap().len(), 0); + + logctx.cleanup_successful(); } } From 320caffc501d2d6d540d9f8e2a9630fbe50c5ef9 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Thu, 28 Jul 2022 11:36:52 -0400 Subject: [PATCH 2/2] clean up earlier for panicking tests --- sled-agent/src/instance.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sled-agent/src/instance.rs b/sled-agent/src/instance.rs index 9e59923b46..883f7d99e8 100644 --- a/sled-agent/src/instance.rs +++ b/sled-agent/src/instance.rs @@ -893,6 +893,10 @@ mod test { ) .unwrap(); + // Remove the logfile before we expect to panic, or it'll never be + // cleaned up. + logctx.cleanup_successful(); + // Trying to transition before the instance has been initialized will // result in a panic. inst.transition(InstanceRuntimeStateRequested { @@ -901,7 +905,5 @@ mod test { }) .await .unwrap(); - - logctx.cleanup_successful(); } }