Omit operations for non-existent users from serialized test plan

This commit is contained in:
Max Brunsfeld 2023-04-05 15:04:27 -07:00
parent 1159f5517b
commit 781d66f628

View file

@ -120,8 +120,8 @@ async fn test_random_collaboration(
let mut operation_channels = Vec::new(); let mut operation_channels = Vec::new();
loop { loop {
let Some((next_operation, skipped)) = plan.lock().next_server_operation(&clients) else { break }; let Some((next_operation, applied)) = plan.lock().next_server_operation(&clients) else { break };
let applied = apply_server_operation( let did_apply = apply_server_operation(
deterministic.clone(), deterministic.clone(),
&mut server, &mut server,
&mut clients, &mut clients,
@ -132,8 +132,8 @@ async fn test_random_collaboration(
cx, cx,
) )
.await; .await;
if !applied { if did_apply {
skipped.store(true, SeqCst); applied.store(true, SeqCst);
} }
} }
@ -1207,8 +1207,8 @@ impl TestPlan {
// Format each operation as one line // Format each operation as one line
let mut json = Vec::new(); let mut json = Vec::new();
json.push(b'['); json.push(b'[');
for (operation, skipped) in &self.stored_operations { for (operation, applied) in &self.stored_operations {
if skipped.load(SeqCst) { if !applied.load(SeqCst) {
continue; continue;
} }
if json.len() > 1 { if json.len() > 1 {
@ -1228,17 +1228,17 @@ impl TestPlan {
if self.replay { if self.replay {
while let Some(stored_operation) = self.stored_operations.get(self.operation_ix) { while let Some(stored_operation) = self.stored_operations.get(self.operation_ix) {
self.operation_ix += 1; self.operation_ix += 1;
if let (StoredOperation::Server(operation), skipped) = stored_operation { if let (StoredOperation::Server(operation), applied) = stored_operation {
return Some((operation.clone(), skipped.clone())); return Some((operation.clone(), applied.clone()));
} }
} }
None None
} else { } else {
let operation = self.generate_server_operation(clients)?; let operation = self.generate_server_operation(clients)?;
let skipped = Arc::new(AtomicBool::new(false)); let applied = Arc::new(AtomicBool::new(false));
self.stored_operations self.stored_operations
.push((StoredOperation::Server(operation.clone()), skipped.clone())); .push((StoredOperation::Server(operation.clone()), applied.clone()));
Some((operation, skipped)) Some((operation, applied))
} }
} }
@ -1263,27 +1263,27 @@ impl TestPlan {
StoredOperation::Client { StoredOperation::Client {
user_id, operation, .. user_id, operation, ..
}, },
skipped, applied,
) = stored_operation ) = stored_operation
{ {
if user_id == &current_user_id { if user_id == &current_user_id {
return Some((operation.clone(), skipped.clone())); return Some((operation.clone(), applied.clone()));
} }
} }
} }
None None
} else { } else {
let operation = self.generate_client_operation(current_user_id, client, cx)?; let operation = self.generate_client_operation(current_user_id, client, cx)?;
let skipped = Arc::new(AtomicBool::new(false)); let applied = Arc::new(AtomicBool::new(false));
self.stored_operations.push(( self.stored_operations.push((
StoredOperation::Client { StoredOperation::Client {
user_id: current_user_id, user_id: current_user_id,
batch_id: current_batch_id, batch_id: current_batch_id,
operation: operation.clone(), operation: operation.clone(),
}, },
skipped.clone(), applied.clone(),
)); ));
Some((operation, skipped)) Some((operation, applied))
} }
} }
@ -1851,11 +1851,14 @@ async fn simulate_client(
client.language_registry.add(Arc::new(language)); client.language_registry.add(Arc::new(language));
while let Some(batch_id) = operation_rx.next().await { while let Some(batch_id) = operation_rx.next().await {
let Some((operation, skipped)) = plan.lock().next_client_operation(&client, batch_id, &cx) else { break }; let Some((operation, applied)) = plan.lock().next_client_operation(&client, batch_id, &cx) else { break };
match apply_client_operation(&client, operation, &mut cx).await { match apply_client_operation(&client, operation, &mut cx).await {
Ok(()) => {} Ok(()) => applied.store(true, SeqCst),
Err(TestError::Inapplicable) => skipped.store(true, SeqCst), Err(TestError::Inapplicable) => {
log::info!("skipped operation");
}
Err(TestError::Other(error)) => { Err(TestError::Other(error)) => {
applied.store(true, SeqCst);
log::error!("{} error: {}", client.username, error); log::error!("{} error: {}", client.username, error);
} }
} }