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
|
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");
|
||||||
|
|
Loading…
Reference in a new issue