Skip to content

Commit

Permalink
fix: Reset quota on configured address change (#5908)
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed Sep 27, 2024
1 parent 78a0d75 commit c2afdf6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ impl Context {
///
/// This should only be used by test code and during configure.
pub(crate) async fn set_primary_self_addr(&self, primary_new: &str) -> Result<()> {
self.quota.write().await.take();

// add old primary address (if exists) to secondary addresses
let mut secondary_addrs = self.get_all_self_addrs().await?;
// never store a primary address also as a secondary
Expand All @@ -869,7 +871,7 @@ impl Context {

self.set_config_internal(Config::ConfiguredAddr, Some(primary_new))
.await?;

self.emit_event(EventType::ConnectivityChanged);
Ok(())
}

Expand Down
11 changes: 10 additions & 1 deletion src/quota.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_quota_needs_update() {
async fn test_quota_needs_update() -> Result<()> {
let mut tcm = TestContextManager::new();
let t = &tcm.unconfigured().await;
const TIMEOUT: u64 = 60;
Expand All @@ -214,5 +214,14 @@ mod tests {
modified: tools::Time::now(),
});
assert!(!t.quota_needs_update(TIMEOUT).await);

t.evtracker.clear_events();
t.set_primary_self_addr("new@addr").await?;
assert!(t.quota.read().await.is_none());
t.evtracker
.get_matching(|evt| matches!(evt, EventType::ConnectivityChanged))
.await;
assert!(t.quota_needs_update(TIMEOUT).await);
Ok(())
}
}

0 comments on commit c2afdf6

Please sign in to comment.