Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Jul 2, 2024
1 parent 65735bf commit 74a4c61
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 504 deletions.
32 changes: 32 additions & 0 deletions nexus/src/app/background/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,9 @@ fn init_dns(

#[cfg(test)]
pub mod test {
use crate::app::saga::SagaStarter;
use dropshot::HandlerTaskMode;
use futures::FutureExt;
use nexus_db_model::DnsGroup;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::datastore::DnsVersionUpdateBuilder;
Expand All @@ -738,9 +740,39 @@ pub mod test {
use nexus_types::internal_api::params as nexus_params;
use omicron_test_utils::dev::poll;
use std::net::SocketAddr;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::time::Duration;
use tempfile::TempDir;

/// Used by various tests of tasks that kick off sagas
pub(crate) struct NoopSagaStarter {
count: AtomicU64,
}

impl NoopSagaStarter {
pub(crate) fn new() -> Self {
Self { count: AtomicU64::new(0) }
}

pub(crate) fn count_reset(&self) -> u64 {
self.count.swap(0, Ordering::SeqCst)
}
}

impl SagaStarter for NoopSagaStarter {
fn saga_start(
&self,
_: steno::SagaDag,
) -> futures::prelude::future::BoxFuture<
'_,
Result<(), omicron_common::api::external::Error>,
> {
let _ = self.count.fetch_add(1, Ordering::SeqCst);
async { Ok(()) }.boxed()
}
}

type ControlPlaneTestContext =
nexus_test_utils::ControlPlaneTestContext<crate::Server>;

Expand Down
12 changes: 5 additions & 7 deletions nexus/src/app/background/tasks/region_replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl BackgroundTask for RegionReplacementDetector {
#[cfg(test)]
mod test {
use super::*;
use crate::app::background::init::test::NoopSagaStarter;
use nexus_db_model::RegionReplacement;
use nexus_test_utils_macros::nexus_test;
use uuid::Uuid;
Expand All @@ -216,10 +217,9 @@ mod test {
datastore.clone(),
);

let mut task = RegionReplacementDetector::new(
datastore.clone(),
nexus.saga_starter(),
);
let starter = Arc::new(NoopSagaStarter::new());
let mut task =
RegionReplacementDetector::new(datastore.clone(), starter.clone());

// Noop test
let result = task.activate(&opctx).await;
Expand Down Expand Up @@ -250,8 +250,6 @@ mod test {
})
);

// XXX-dap
// saga_request_rx.try_recv().unwrap();
todo!();
assert_eq!(starter.count_reset(), 1);
}
}
Loading

0 comments on commit 74a4c61

Please sign in to comment.