fix(net): prevent race to match mocked net requests
This commit is contained in:
parent
d3eb51ab73
commit
31354f74ef
1 changed files with 4 additions and 5 deletions
|
@ -62,7 +62,7 @@ impl Plan {
|
|||
},
|
||||
),
|
||||
});
|
||||
tracing::debug!(?is_match);
|
||||
tracing::debug!(?is_match, plan = ?self);
|
||||
is_match
|
||||
}
|
||||
}
|
||||
|
@ -140,16 +140,15 @@ impl Net {
|
|||
};
|
||||
tracing::debug!("build request");
|
||||
let request = request.build()?;
|
||||
let index = plans
|
||||
.lock()
|
||||
.await
|
||||
let locked_plans = plans.lock().await;
|
||||
let index = locked_plans
|
||||
.deref()
|
||||
.borrow()
|
||||
.iter()
|
||||
.position(|plan| plan.matches(&request));
|
||||
match index {
|
||||
Some(i) => {
|
||||
let plan = plans.lock().await.borrow_mut().remove(i);
|
||||
let plan = locked_plans.borrow_mut().remove(i);
|
||||
let response = plan.response;
|
||||
if response.status().is_success() {
|
||||
tracing::debug!(?request, "matched success response");
|
||||
|
|
Loading…
Reference in a new issue