Start work on allowing random collab test to be minimized
Represent operations as an explicit enum.
This commit is contained in:
parent
83c98ce049
commit
a74c5073a4
3 changed files with 439 additions and 193 deletions
|
@ -21,8 +21,9 @@ use parking_lot::Mutex;
|
||||||
use project::{Project, WorktreeId};
|
use project::{Project, WorktreeId};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use std::{
|
use std::{
|
||||||
|
cell::{Ref, RefCell, RefMut},
|
||||||
env,
|
env,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
|
atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
|
||||||
|
@ -218,13 +219,10 @@ impl TestServer {
|
||||||
let client = TestClient {
|
let client = TestClient {
|
||||||
client,
|
client,
|
||||||
username: name.to_string(),
|
username: name.to_string(),
|
||||||
local_projects: Default::default(),
|
state: Default::default(),
|
||||||
remote_projects: Default::default(),
|
|
||||||
next_root_dir_id: 0,
|
|
||||||
user_store,
|
user_store,
|
||||||
fs,
|
fs,
|
||||||
language_registry: Arc::new(LanguageRegistry::test()),
|
language_registry: Arc::new(LanguageRegistry::test()),
|
||||||
buffers: Default::default(),
|
|
||||||
};
|
};
|
||||||
client.wait_for_current_user(cx).await;
|
client.wait_for_current_user(cx).await;
|
||||||
client
|
client
|
||||||
|
@ -323,13 +321,18 @@ impl Drop for TestServer {
|
||||||
struct TestClient {
|
struct TestClient {
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
username: String,
|
username: String,
|
||||||
local_projects: Vec<ModelHandle<Project>>,
|
state: RefCell<TestClientState>,
|
||||||
remote_projects: Vec<ModelHandle<Project>>,
|
|
||||||
next_root_dir_id: usize,
|
|
||||||
pub user_store: ModelHandle<UserStore>,
|
pub user_store: ModelHandle<UserStore>,
|
||||||
language_registry: Arc<LanguageRegistry>,
|
language_registry: Arc<LanguageRegistry>,
|
||||||
fs: Arc<FakeFs>,
|
fs: Arc<FakeFs>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct TestClientState {
|
||||||
|
local_projects: Vec<ModelHandle<Project>>,
|
||||||
|
remote_projects: Vec<ModelHandle<Project>>,
|
||||||
buffers: HashMap<ModelHandle<Project>, HashSet<ModelHandle<language::Buffer>>>,
|
buffers: HashMap<ModelHandle<Project>, HashSet<ModelHandle<language::Buffer>>>,
|
||||||
|
next_root_dir_id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for TestClient {
|
impl Deref for TestClient {
|
||||||
|
@ -367,6 +370,38 @@ impl TestClient {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<ModelHandle<Project>>> + 'a {
|
||||||
|
Ref::map(self.state.borrow(), |state| &state.local_projects)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<ModelHandle<Project>>> + 'a {
|
||||||
|
Ref::map(self.state.borrow(), |state| &state.remote_projects)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<ModelHandle<Project>>> + 'a {
|
||||||
|
RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<ModelHandle<Project>>> + 'a {
|
||||||
|
RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffers_for_project<'a>(
|
||||||
|
&'a self,
|
||||||
|
project: &ModelHandle<Project>,
|
||||||
|
) -> impl DerefMut<Target = HashSet<ModelHandle<language::Buffer>>> + 'a {
|
||||||
|
RefMut::map(self.state.borrow_mut(), |state| {
|
||||||
|
state.buffers.entry(project.clone()).or_default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn buffers<'a>(
|
||||||
|
&'a self,
|
||||||
|
) -> impl DerefMut<Target = HashMap<ModelHandle<Project>, HashSet<ModelHandle<language::Buffer>>>> + 'a
|
||||||
|
{
|
||||||
|
RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
|
||||||
|
}
|
||||||
|
|
||||||
fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
|
fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
|
||||||
self.user_store.read_with(cx, |store, _| ContactsSummary {
|
self.user_store.read_with(cx, |store, _| ContactsSummary {
|
||||||
current: store
|
current: store
|
||||||
|
@ -449,11 +484,11 @@ impl TestClient {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_new_root_dir(&mut self) -> PathBuf {
|
fn create_new_root_dir(&self) -> PathBuf {
|
||||||
format!(
|
format!(
|
||||||
"/{}-root-{}",
|
"/{}-root-{}",
|
||||||
self.username,
|
self.username,
|
||||||
util::post_inc(&mut self.next_root_dir_id)
|
util::post_inc(&mut self.state.borrow_mut().next_root_dir_id)
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -27,6 +27,7 @@ use collections::BTreeMap;
|
||||||
|
|
||||||
use super::{AsyncAppContext, RefCounts};
|
use super::{AsyncAppContext, RefCounts};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct TestAppContext {
|
pub struct TestAppContext {
|
||||||
cx: Rc<RefCell<MutableAppContext>>,
|
cx: Rc<RefCell<MutableAppContext>>,
|
||||||
foreground_platform: Rc<platform::test::ForegroundPlatform>,
|
foreground_platform: Rc<platform::test::ForegroundPlatform>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue