Randomly detach requests on guest to let them race with other local ops

This commit is contained in:
Antonio Scandurra 2022-02-17 09:05:06 +01:00
parent e3c4ce208a
commit 1fbcea6c0d
3 changed files with 58 additions and 26 deletions

View File

@ -492,6 +492,15 @@ impl TestAppContext {
self.cx.borrow().background().clone() self.cx.borrow().background().clone()
} }
pub fn spawn<F, Fut, T>(&self, f: F) -> Task<T>
where
F: FnOnce(AsyncAppContext) -> Fut,
Fut: 'static + Future<Output = T>,
T: 'static,
{
self.cx.borrow_mut().spawn(f)
}
pub fn simulate_new_path_selection(&self, result: impl FnOnce(PathBuf) -> Option<PathBuf>) { pub fn simulate_new_path_selection(&self, result: impl FnOnce(PathBuf) -> Option<PathBuf>) {
self.foreground_platform.simulate_new_path_selection(result); self.foreground_platform.simulate_new_path_selection(result);
} }

View File

@ -1580,6 +1580,7 @@ impl Project {
} else if let Some(project_id) = self.remote_id() { } else if let Some(project_id) = self.remote_id() {
let rpc = self.client.clone(); let rpc = self.client.clone();
cx.foreground().spawn(async move { cx.foreground().spawn(async move {
let _buffer = buffer_handle.clone();
let response = rpc let response = rpc
.request(proto::GetCodeActions { .request(proto::GetCodeActions {
project_id, project_id,

View File

@ -4169,6 +4169,8 @@ mod tests {
self.buffers.insert(buffer.clone()); self.buffers.insert(buffer.clone());
buffer buffer
} else { } else {
operations.set(operations.get() + 1);
self.buffers self.buffers
.iter() .iter()
.choose(&mut *rng.borrow_mut()) .choose(&mut *rng.borrow_mut())
@ -4190,30 +4192,42 @@ mod tests {
}); });
} }
10..=14 => { 10..=14 => {
project let completions = project.update(&mut cx, |project, cx| {
.update(&mut cx, |project, cx| { log::info!(
log::info!( "Guest {}: requesting completions for buffer {:?}",
"Guest {}: requesting completions for buffer {:?}", guest_id,
guest_id, buffer.read(cx).file().unwrap().full_path(cx)
buffer.read(cx).file().unwrap().full_path(cx) );
); project.completions(&buffer, 0, cx)
project.completions(&buffer, 0, cx) });
}) let completions = cx.background().spawn(async move {
.await completions.await.expect("code actions request failed");
.expect("completion request failed"); });
if rng.borrow_mut().gen_bool(0.3) {
log::info!("Guest {}: detaching completions request", guest_id);
completions.detach();
} else {
completions.await;
}
} }
15..=19 => { 15..=19 => {
project let code_actions = project.update(&mut cx, |project, cx| {
.update(&mut cx, |project, cx| { log::info!(
log::info!( "Guest {}: requesting code actions for buffer {:?}",
"Guest {}: requesting code actions for buffer {:?}", guest_id,
guest_id, buffer.read(cx).file().unwrap().full_path(cx)
buffer.read(cx).file().unwrap().full_path(cx) );
); project.code_actions(&buffer, 0..0, cx)
project.code_actions(&buffer, 0..0, cx) });
}) let code_actions = cx.background().spawn(async move {
.await code_actions.await.expect("code actions request failed");
.expect("completion request failed"); });
if rng.borrow_mut().gen_bool(0.3) {
log::info!("Guest {}: detaching code actions request", guest_id);
code_actions.detach();
} else {
code_actions.await;
}
} }
20..=29 if buffer.read_with(&cx, |buffer, _| buffer.is_dirty()) => { 20..=29 if buffer.read_with(&cx, |buffer, _| buffer.is_dirty()) => {
let (requested_version, save) = buffer.update(&mut cx, |buffer, cx| { let (requested_version, save) = buffer.update(&mut cx, |buffer, cx| {
@ -4224,11 +4238,19 @@ mod tests {
); );
(buffer.version(), buffer.save(cx)) (buffer.version(), buffer.save(cx))
}); });
let (saved_version, _) = save.await.expect("completion request failed"); let save = cx.spawn(|cx| async move {
buffer.read_with(&cx, |buffer, _| { let (saved_version, _) = save.await.expect("save request failed");
assert!(buffer.version().observed_all(&saved_version)); buffer.read_with(&cx, |buffer, _| {
assert!(saved_version.observed_all(&requested_version)); assert!(buffer.version().observed_all(&saved_version));
assert!(saved_version.observed_all(&requested_version));
});
}); });
if rng.borrow_mut().gen_bool(0.3) {
log::info!("Guest {}: detaching save request", guest_id);
save.detach();
} else {
save.await;
}
} }
_ => { _ => {
buffer.update(&mut cx, |buffer, cx| { buffer.update(&mut cx, |buffer, cx| {