Skip to content

Commit aacea2d

Browse files
committed
fix: Reset quota on configured address change (#5908)
1 parent b713e8c commit aacea2d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,8 @@ impl Context {
857857
///
858858
/// This should only be used by test code and during configure.
859859
pub(crate) async fn set_primary_self_addr(&self, primary_new: &str) -> Result<()> {
860+
self.quota.write().await.take();
861+
860862
// add old primary address (if exists) to secondary addresses
861863
let mut secondary_addrs = self.get_all_self_addrs().await?;
862864
// never store a primary address also as a secondary
@@ -869,7 +871,7 @@ impl Context {
869871

870872
self.set_config_internal(Config::ConfiguredAddr, Some(primary_new))
871873
.await?;
872-
874+
self.emit_event(EventType::ConnectivityChanged);
873875
Ok(())
874876
}
875877

src/quota.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod tests {
197197
}
198198

199199
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
200-
async fn test_quota_needs_update() {
200+
async fn test_quota_needs_update() -> Result<()> {
201201
let mut tcm = TestContextManager::new();
202202
let t = &tcm.unconfigured().await;
203203
const TIMEOUT: u64 = 60;
@@ -214,5 +214,14 @@ mod tests {
214214
modified: tools::Time::now(),
215215
});
216216
assert!(!t.quota_needs_update(TIMEOUT).await);
217+
218+
t.evtracker.clear_events();
219+
t.set_primary_self_addr("new@addr").await?;
220+
assert!(t.quota.read().await.is_none());
221+
t.evtracker
222+
.get_matching(|evt| matches!(evt, EventType::ConnectivityChanged))
223+
.await;
224+
assert!(t.quota_needs_update(TIMEOUT).await);
225+
Ok(())
217226
}
218227
}

0 commit comments

Comments
 (0)