From 02d66b8a5d3f126067828005042d33c274b6aab8 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Mon, 9 Jan 2023 13:24:28 +0000 Subject: [PATCH] Reset registered regions on setup call. This ensures that each test will reset the regions hashmap. --- chirpstack/src/config.rs | 4 ++-- chirpstack/src/region.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/chirpstack/src/config.rs b/chirpstack/src/config.rs index de1e8db1..786a7fea 100644 --- a/chirpstack/src/config.rs +++ b/chirpstack/src/config.rs @@ -742,7 +742,7 @@ pub fn get_region_network(region_id: &str) -> Result { } } - Err(anyhow!("region_id not found")) + Err(anyhow!("Region ID '{}' not found", region_id)) } pub fn get_region_gateway(region_id: &str) -> Result { @@ -753,7 +753,7 @@ pub fn get_region_gateway(region_id: &str) -> Result { } } - Err(anyhow!("region_id not found")) + Err(anyhow!("Region ID '{}' not found", region_id)) } pub fn get_required_snr_for_sf(sf: u8) -> Result { diff --git a/chirpstack/src/region.rs b/chirpstack/src/region.rs index 85245f3d..1e622753 100644 --- a/chirpstack/src/region.rs +++ b/chirpstack/src/region.rs @@ -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) { let mut regions_w = REGIONS.write().unwrap(); regions_w.insert(region_config_id.to_string(), Arc::new(r));