Skip to content

Commit 31bfdd9

Browse files
committed
[amazon_rose_forest] test runtime
1 parent dfd2633 commit 31bfdd9

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ rand_distr = "0.4"
2929
sha2 = "0.10.7" # Added SHA-2 cryptographic hash functions
3030
sha3 = { version = "0.10", optional = true }
3131
blake3 = { version = "1", optional = true }
32-
rand = "0.8"
3332
serde_bytes = "0.11"
3433
wide = "0.7"
3534
warp = "0.3"

src/nerv/runtime.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ impl Runtime {
7373
pub fn shard_manager(&self) -> Option<Arc<ShardManager>> {
7474
self.shard_manager.clone()
7575
}
76+
77+
/// Expose the shutdown sender for testing and external monitoring
78+
pub fn shutdown_sender(&self) -> Option<mpsc::Sender<()>> {
79+
self.shutdown_tx.clone()
80+
}
7681
}

tests/runtime.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use amazon_rose_forest::{core::metrics::MetricsCollector, nerv::runtime::Runtime};
2+
use std::sync::Arc;
3+
use tokio::time::{timeout, Duration};
4+
5+
#[tokio::test]
6+
async fn runtime_start_initializes_shard_manager() {
7+
let metrics = Arc::new(MetricsCollector::new());
8+
let mut runtime = Runtime::new(metrics.clone());
9+
runtime.start().await.unwrap();
10+
assert!(runtime.shard_manager().is_some());
11+
runtime.stop().await.unwrap();
12+
}
13+
14+
#[tokio::test]
15+
async fn runtime_stop_sends_shutdown_signal() {
16+
let metrics = Arc::new(MetricsCollector::new());
17+
let mut runtime = Runtime::new(metrics);
18+
runtime.start().await.unwrap();
19+
20+
runtime.stop().await.unwrap();
21+
22+
if let Some(tx) = runtime.shutdown_sender() {
23+
// The channel should close once the background task handles the shutdown message
24+
let closed = timeout(Duration::from_secs(1), tx.closed()).await;
25+
assert!(closed.is_ok(), "shutdown signal not processed in time");
26+
} else {
27+
panic!("shutdown channel missing");
28+
}
29+
}

0 commit comments

Comments
 (0)