Merge pull request #801 from zed-industries/randomized-test-improvements
Introduce guest disconnection in randomized collaboration test
This commit is contained in:
@@ -15,6 +15,7 @@ required-features = ["seed-support"]
|
||||
[dependencies]
|
||||
collections = { path = "../collections" }
|
||||
rpc = { path = "../rpc" }
|
||||
util = { path = "../util" }
|
||||
anyhow = "1.0.40"
|
||||
async-io = "1.3"
|
||||
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||
|
||||
+458
-274
File diff suppressed because it is too large
Load Diff
@@ -130,9 +130,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -275,8 +272,6 @@ impl Store {
|
||||
share.worktrees.insert(worktree_id, Default::default());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("no such project"))?
|
||||
@@ -313,8 +308,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
Ok(project)
|
||||
} else {
|
||||
Err(anyhow!("no such project"))?
|
||||
@@ -359,9 +352,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok((worktree, guest_connection_ids))
|
||||
}
|
||||
|
||||
@@ -403,9 +393,6 @@ impl Store {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok(UnsharedProject {
|
||||
connection_ids,
|
||||
authorized_user_ids,
|
||||
@@ -491,9 +478,6 @@ impl Store {
|
||||
share.active_replica_ids.insert(replica_id);
|
||||
share.guests.insert(connection_id, (replica_id, user_id));
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok(JoinedProject {
|
||||
replica_id,
|
||||
project: &self.projects[&project_id],
|
||||
@@ -526,9 +510,6 @@ impl Store {
|
||||
let connection_ids = project.connection_ids();
|
||||
let authorized_user_ids = project.authorized_user_ids();
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok(LeftProject {
|
||||
connection_ids,
|
||||
authorized_user_ids,
|
||||
@@ -556,10 +537,6 @@ impl Store {
|
||||
worktree.entries.insert(entry.id, entry.clone());
|
||||
}
|
||||
let connection_ids = project.connection_ids();
|
||||
|
||||
#[cfg(test)]
|
||||
self.check_invariants();
|
||||
|
||||
Ok(connection_ids)
|
||||
}
|
||||
|
||||
@@ -633,7 +610,7 @@ impl Store {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn check_invariants(&self) {
|
||||
pub fn check_invariants(&self) {
|
||||
for (connection_id, connection) in &self.connections {
|
||||
for project_id in &connection.projects {
|
||||
let project = &self.projects.get(&project_id).unwrap();
|
||||
|
||||
@@ -75,68 +75,65 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||
match last_segment.map(|s| s.ident.to_string()).as_deref() {
|
||||
Some("StdRng") => {
|
||||
inner_fn_args.extend(quote!(rand::SeedableRng::seed_from_u64(seed),));
|
||||
continue;
|
||||
}
|
||||
Some("bool") => {
|
||||
inner_fn_args.extend(quote!(is_last_iteration,));
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument")
|
||||
.into_compile_error(),
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if let Type::Reference(ty) = &*arg.ty {
|
||||
match &*ty.elem {
|
||||
Type::Path(ty) => {
|
||||
let last_segment = ty.path.segments.last();
|
||||
match last_segment.map(|s| s.ident.to_string()).as_deref() {
|
||||
Some("TestAppContext") => {
|
||||
let first_entity_id = ix * 100_000;
|
||||
let cx_varname = format_ident!("cx_{}", ix);
|
||||
cx_vars.extend(quote!(
|
||||
let mut #cx_varname = #namespace::TestAppContext::new(
|
||||
foreground_platform.clone(),
|
||||
cx.platform().clone(),
|
||||
deterministic.build_foreground(#ix),
|
||||
deterministic.build_background(),
|
||||
cx.font_cache().clone(),
|
||||
cx.leak_detector(),
|
||||
#first_entity_id,
|
||||
);
|
||||
));
|
||||
cx_teardowns.extend(quote!(
|
||||
#cx_varname.update(|cx| cx.remove_all_windows());
|
||||
deterministic.run_until_parked();
|
||||
#cx_varname.update(|_| {}); // flush effects
|
||||
));
|
||||
inner_fn_args.extend(quote!(&mut #cx_varname,));
|
||||
}
|
||||
_ => {
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument")
|
||||
.into_compile_error(),
|
||||
)
|
||||
Some("Arc") => {
|
||||
if let syn::PathArguments::AngleBracketed(args) =
|
||||
&last_segment.unwrap().arguments
|
||||
{
|
||||
if let Some(syn::GenericArgument::Type(syn::Type::Path(ty))) =
|
||||
args.args.last()
|
||||
{
|
||||
let last_segment = ty.path.segments.last();
|
||||
if let Some("Deterministic") =
|
||||
last_segment.map(|s| s.ident.to_string()).as_deref()
|
||||
{
|
||||
inner_fn_args.extend(quote!(deterministic.clone(),));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument")
|
||||
.into_compile_error(),
|
||||
)
|
||||
_ => {}
|
||||
}
|
||||
} else if let Type::Reference(ty) = &*arg.ty {
|
||||
if let Type::Path(ty) = &*ty.elem {
|
||||
let last_segment = ty.path.segments.last();
|
||||
if let Some("TestAppContext") =
|
||||
last_segment.map(|s| s.ident.to_string()).as_deref()
|
||||
{
|
||||
let first_entity_id = ix * 100_000;
|
||||
let cx_varname = format_ident!("cx_{}", ix);
|
||||
cx_vars.extend(quote!(
|
||||
let mut #cx_varname = #namespace::TestAppContext::new(
|
||||
foreground_platform.clone(),
|
||||
cx.platform().clone(),
|
||||
deterministic.build_foreground(#ix),
|
||||
deterministic.build_background(),
|
||||
cx.font_cache().clone(),
|
||||
cx.leak_detector(),
|
||||
#first_entity_id,
|
||||
);
|
||||
));
|
||||
cx_teardowns.extend(quote!(
|
||||
#cx_varname.update(|cx| cx.remove_all_windows());
|
||||
deterministic.run_until_parked();
|
||||
#cx_varname.update(|_| {}); // flush effects
|
||||
));
|
||||
inner_fn_args.extend(quote!(&mut #cx_varname,));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument").into_compile_error(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument").into_compile_error(),
|
||||
);
|
||||
}
|
||||
|
||||
return TokenStream::from(
|
||||
syn::Error::new_spanned(arg, "invalid argument").into_compile_error(),
|
||||
);
|
||||
}
|
||||
|
||||
parse_quote! {
|
||||
|
||||
@@ -126,7 +126,11 @@ impl Peer {
|
||||
// can always send messages without yielding. For incoming messages, use a
|
||||
// bounded channel so that other peers will receive backpressure if they send
|
||||
// messages faster than this peer can process them.
|
||||
let (mut incoming_tx, incoming_rx) = mpsc::channel(64);
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
const INCOMING_BUFFER_SIZE: usize = 1;
|
||||
#[cfg(not(any(test, feature = "test-support")))]
|
||||
const INCOMING_BUFFER_SIZE: usize = 64;
|
||||
let (mut incoming_tx, incoming_rx) = mpsc::channel(INCOMING_BUFFER_SIZE);
|
||||
let (outgoing_tx, mut outgoing_rx) = mpsc::unbounded();
|
||||
|
||||
let connection_id = ConnectionId(self.next_connection_id.fetch_add(1, SeqCst));
|
||||
|
||||
Reference in New Issue
Block a user