From ae62850d6e9b7c4d1de622bd03d099ff5c928361 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Fri, 29 Jul 2022 09:56:41 -0400 Subject: [PATCH] Quiet sled agent tests (#1512) * Quiet sled agent tests * clean up earlier for panicking tests --- sled-agent/src/instance.rs | 16 +++++++--------- sled-agent/src/instance_manager.rs | 23 +++++++++++------------ 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/sled-agent/src/instance.rs b/sled-agent/src/instance.rs index 15a8672666..883f7d99e8 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()), @@ -899,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 { 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(); } }