Close buffers in randomized integration test

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-02-16 17:55:28 +01:00
parent 7c5a5c4ad4
commit 0173025f4b
2 changed files with 45 additions and 22 deletions

View file

@ -46,7 +46,7 @@ pub struct Project {
collaborators: HashMap<PeerId, Collaborator>, collaborators: HashMap<PeerId, Collaborator>,
subscriptions: Vec<client::Subscription>, subscriptions: Vec<client::Subscription>,
language_servers_with_diagnostics_running: isize, language_servers_with_diagnostics_running: isize,
open_buffers: HashMap<usize, OpenBuffer>, open_buffers: HashMap<u64, OpenBuffer>,
opened_buffer: broadcast::Sender<()>, opened_buffer: broadcast::Sender<()>,
loading_buffers: HashMap< loading_buffers: HashMap<
ProjectPath, ProjectPath,
@ -719,7 +719,7 @@ impl Project {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Result<()> { ) -> Result<()> {
match self.open_buffers.insert( match self.open_buffers.insert(
buffer.read(cx).remote_id() as usize, buffer.read(cx).remote_id(),
OpenBuffer::Loaded(buffer.downgrade()), OpenBuffer::Loaded(buffer.downgrade()),
) { ) {
None => {} None => {}
@ -2183,7 +2183,7 @@ impl Project {
) -> Result<()> { ) -> Result<()> {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let payload = envelope.payload.clone(); let payload = envelope.payload.clone();
let buffer_id = payload.buffer_id as usize; let buffer_id = payload.buffer_id;
let ops = payload let ops = payload
.operations .operations
.into_iter() .into_iter()
@ -2213,7 +2213,7 @@ impl Project {
) -> Result<()> { ) -> Result<()> {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let payload = envelope.payload.clone(); let payload = envelope.payload.clone();
let buffer_id = payload.buffer_id as usize; let buffer_id = payload.buffer_id;
let file = payload.file.ok_or_else(|| anyhow!("invalid file"))?; let file = payload.file.ok_or_else(|| anyhow!("invalid file"))?;
let worktree = this let worktree = this
.worktree_for_id(WorktreeId::from_proto(file.worktree_id), cx) .worktree_for_id(WorktreeId::from_proto(file.worktree_id), cx)
@ -2601,7 +2601,7 @@ impl Project {
let buffer = loop { let buffer = loop {
let buffer = this.read_with(&cx, |this, cx| { let buffer = this.read_with(&cx, |this, cx| {
this.open_buffers this.open_buffers
.get(&(id as usize)) .get(&id)
.and_then(|buffer| buffer.upgrade(cx)) .and_then(|buffer| buffer.upgrade(cx))
}); });
if let Some(buffer) = buffer { if let Some(buffer) = buffer {
@ -2679,7 +2679,7 @@ impl Project {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let buffer = this let buffer = this
.open_buffers .open_buffers
.get(&(envelope.payload.buffer_id as usize)) .get(&envelope.payload.buffer_id)
.and_then(|buffer| buffer.upgrade(cx)); .and_then(|buffer| buffer.upgrade(cx));
if let Some(buffer) = buffer { if let Some(buffer) = buffer {
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
@ -2705,7 +2705,7 @@ impl Project {
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
let buffer = this let buffer = this
.open_buffers .open_buffers
.get(&(payload.buffer_id as usize)) .get(&payload.buffer_id)
.and_then(|buffer| buffer.upgrade(cx)); .and_then(|buffer| buffer.upgrade(cx));
if let Some(buffer) = buffer { if let Some(buffer) = buffer {
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {

View file

@ -4007,13 +4007,24 @@ mod tests {
.clone() .clone()
}; };
buffer.update(&mut cx, |buffer, cx| { if rng.borrow_mut().gen_bool(0.1) {
log::info!( cx.update(|cx| {
"Host: updating buffer {:?}", log::info!(
buffer.file().unwrap().full_path(cx) "Host: dropping buffer {:?}",
); buffer.read(cx).file().unwrap().full_path(cx)
buffer.randomly_edit(&mut *rng.borrow_mut(), 5, cx) );
}); self.buffers.remove(&buffer);
drop(buffer);
});
} else {
buffer.update(&mut cx, |buffer, cx| {
log::info!(
"Host: updating buffer {:?}",
buffer.file().unwrap().full_path(cx)
);
buffer.randomly_edit(&mut *rng.borrow_mut(), 5, cx)
});
}
} }
_ => loop { _ => loop {
let path_component_count = rng.borrow_mut().gen_range(1..=5); let path_component_count = rng.borrow_mut().gen_range(1..=5);
@ -4093,14 +4104,26 @@ mod tests {
.clone() .clone()
}; };
buffer.update(&mut cx, |buffer, cx| { if rng.borrow_mut().gen_bool(0.1) {
log::info!( cx.update(|cx| {
"Guest {}: updating buffer {:?}", log::info!(
guest_id, "Guest {}: dropping buffer {:?}",
buffer.file().unwrap().full_path(cx) guest_id,
); buffer.read(cx).file().unwrap().full_path(cx)
buffer.randomly_edit(&mut *rng.borrow_mut(), 5, cx) );
}); self.buffers.remove(&buffer);
drop(buffer);
});
} else {
buffer.update(&mut cx, |buffer, cx| {
log::info!(
"Guest {}: updating buffer {:?}",
guest_id,
buffer.file().unwrap().full_path(cx)
);
buffer.randomly_edit(&mut *rng.borrow_mut(), 5, cx)
});
}
cx.background().simulate_random_delay().await; cx.background().simulate_random_delay().await;
} }