fix(net): prevent race to match mocked net requests
All checks were successful
Test / build (map[name:stable]) (push) Successful in 7m54s
Test / build (map[name:nightly]) (push) Successful in 6m40s
Release Please / Release-plz (push) Successful in 1m26s

This commit is contained in:
Paul Campbell 2024-12-25 19:17:59 +00:00
parent d3eb51ab73
commit 31354f74ef

View file

@ -62,7 +62,7 @@ impl Plan {
}, },
), ),
}); });
tracing::debug!(?is_match); tracing::debug!(?is_match, plan = ?self);
is_match is_match
} }
} }
@ -140,16 +140,15 @@ impl Net {
}; };
tracing::debug!("build request"); tracing::debug!("build request");
let request = request.build()?; let request = request.build()?;
let index = plans let locked_plans = plans.lock().await;
.lock() let index = locked_plans
.await
.deref() .deref()
.borrow() .borrow()
.iter() .iter()
.position(|plan| plan.matches(&request)); .position(|plan| plan.matches(&request));
match index { match index {
Some(i) => { Some(i) => {
let plan = plans.lock().await.borrow_mut().remove(i); let plan = locked_plans.borrow_mut().remove(i);
let response = plan.response; let response = plan.response;
if response.status().is_success() { if response.status().is_success() {
tracing::debug!(?request, "matched success response"); tracing::debug!(?request, "matched success response");