Reset registered regions on setup call.

This ensures that each test will reset the regions hashmap.
This commit is contained in:
Orne Brocaar 2023-01-09 13:24:28 +00:00
parent e78dac316a
commit 02d66b8a5d
2 changed files with 9 additions and 2 deletions

View File

@ -742,7 +742,7 @@ pub fn get_region_network(region_id: &str) -> Result<RegionNetwork> {
}
}
Err(anyhow!("region_id not found"))
Err(anyhow!("Region ID '{}' not found", region_id))
}
pub fn get_region_gateway(region_id: &str) -> Result<RegionGateway> {
@ -753,7 +753,7 @@ pub fn get_region_gateway(region_id: &str) -> Result<RegionGateway> {
}
}
Err(anyhow!("region_id not found"))
Err(anyhow!("Region ID '{}' not found", region_id))
}
pub fn get_required_snr_for_sf(sf: u8) -> Result<f32> {

View File

@ -16,6 +16,8 @@ pub fn setup() -> Result<()> {
info!("Setting up regions");
let conf = config::get();
reset();
for r in &conf.regions {
let span = span!(Level::INFO, "setup", common_name = %r.common_name, region_id = %r.id);
let _guard = span.enter();
@ -63,6 +65,11 @@ pub fn setup() -> Result<()> {
Ok(())
}
fn reset() {
let mut regions_w = REGIONS.write().unwrap();
regions_w.clear();
}
pub fn set(region_config_id: &str, r: Box<dyn region::Region + Sync + Send>) {
let mut regions_w = REGIONS.write().unwrap();
regions_w.insert(region_config_id.to_string(), Arc::new(r));