44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
use std::{fs, path::PathBuf, thread, time::Duration};
|
|
|
|
use api::PlacementStore;
|
|
|
|
fn tmp_file(name: &str) -> PathBuf {
|
|
let mut p = std::env::temp_dir();
|
|
p.push(format!(
|
|
"cloudlysis-control-{name}-{}-{}.json",
|
|
std::process::id(),
|
|
std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_nanos()
|
|
));
|
|
p
|
|
}
|
|
|
|
#[test]
|
|
fn placement_store_hot_reload_swaps_atomically() {
|
|
let path = tmp_file("placement");
|
|
fs::write(
|
|
&path,
|
|
r#"{"revision":"r1","aggregate_placement":{"placements":[]},"projection_placement":{"placements":[]},"runner_placement":{"placements":[]}}"#,
|
|
)
|
|
.unwrap();
|
|
|
|
let store = PlacementStore::new(path.clone());
|
|
let a1 = store.get_for_kind(api::ServiceKind::Aggregate);
|
|
assert_eq!(a1.revision, "r1");
|
|
|
|
thread::sleep(Duration::from_millis(5));
|
|
|
|
fs::write(
|
|
&path,
|
|
r#"{"revision":"r2","aggregate_placement":{"placements":[]},"projection_placement":{"placements":[]},"runner_placement":{"placements":[]}}"#,
|
|
)
|
|
.unwrap();
|
|
|
|
let a2 = store.get_for_kind(api::ServiceKind::Aggregate);
|
|
assert_eq!(a2.revision, "r2");
|
|
|
|
let _ = fs::remove_file(&path);
|
|
}
|