Skip to content

Commit

Permalink
Quiet sled agent tests (#1512)
Browse files Browse the repository at this point in the history
* Quiet sled agent tests

* clean up earlier for panicking tests
  • Loading branch information
smklein authored Jul 29, 2022
1 parent bdd49e9 commit ae62850
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
16 changes: 7 additions & 9 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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()),
Expand All @@ -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 {
Expand Down
23 changes: 11 additions & 12 deletions sled-agent/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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();
}
}

0 comments on commit ae62850

Please sign in to comment.