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()
}
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>) {
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() {
let rpc = self.client.clone();
cx.foreground().spawn(async move {
let _buffer = buffer_handle.clone();
let response = rpc
.request(proto::GetCodeActions {
project_id,

View File

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