Add randomized test to remove active selections from buffer

This commit is contained in:
Antonio Scandurra 2023-03-09 07:42:37 +01:00
parent 4ce51c8138
commit a00ce3f286

View File

@ -1804,25 +1804,31 @@ fn test_random_collaboration(cx: &mut MutableAppContext, mut rng: StdRng) {
} }
30..=39 if mutation_count != 0 => { 30..=39 if mutation_count != 0 => {
buffer.update(cx, |buffer, cx| { buffer.update(cx, |buffer, cx| {
let mut selections = Vec::new(); if rng.gen_bool(0.2) {
for id in 0..rng.gen_range(1..=5) { log::info!("peer {} clearing active selections", replica_id);
let range = buffer.random_byte_range(0, &mut rng); active_selections.remove(&replica_id);
selections.push(Selection { buffer.remove_active_selections(cx);
id, } else {
start: buffer.anchor_before(range.start), let mut selections = Vec::new();
end: buffer.anchor_before(range.end), for id in 0..rng.gen_range(1..=5) {
reversed: false, let range = buffer.random_byte_range(0, &mut rng);
goal: SelectionGoal::None, selections.push(Selection {
}); id,
start: buffer.anchor_before(range.start),
end: buffer.anchor_before(range.end),
reversed: false,
goal: SelectionGoal::None,
});
}
let selections: Arc<[Selection<Anchor>]> = selections.into();
log::info!(
"peer {} setting active selections: {:?}",
replica_id,
selections
);
active_selections.insert(replica_id, selections.clone());
buffer.set_active_selections(selections, false, Default::default(), cx);
} }
let selections: Arc<[Selection<Anchor>]> = selections.into();
log::info!(
"peer {} setting active selections: {:?}",
replica_id,
selections
);
active_selections.insert(replica_id, selections.clone());
buffer.set_active_selections(selections, false, Default::default(), cx);
}); });
mutation_count -= 1; mutation_count -= 1;
} }