Ensure that usernames, user ids, and client ids match in random collaboration test
This makes the logs easier to interpret
This commit is contained in:
parent
4ee8ee5a06
commit
c5351a1276
3 changed files with 21 additions and 17 deletions
|
@ -28,10 +28,7 @@ use std::{
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
fmt::Write as _,
|
fmt::Write as _,
|
||||||
future::Future,
|
future::Future,
|
||||||
sync::{
|
sync::{Arc, Weak},
|
||||||
atomic::{AtomicUsize, Ordering},
|
|
||||||
Arc, Weak,
|
|
||||||
},
|
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -232,12 +229,8 @@ impl Drop for Subscription {
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn new(http: Arc<dyn HttpClient>) -> Arc<Self> {
|
pub fn new(http: Arc<dyn HttpClient>) -> Arc<Self> {
|
||||||
lazy_static! {
|
|
||||||
static ref NEXT_CLIENT_ID: AtomicUsize = AtomicUsize::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
id: NEXT_CLIENT_ID.fetch_add(1, Ordering::SeqCst),
|
id: 0,
|
||||||
peer: Peer::new(),
|
peer: Peer::new(),
|
||||||
http,
|
http,
|
||||||
state: Default::default(),
|
state: Default::default(),
|
||||||
|
@ -257,6 +250,12 @@ impl Client {
|
||||||
self.http.clone()
|
self.http.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn set_id(&mut self, id: usize) -> &Self {
|
||||||
|
self.id = id;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn tear_down(&self) {
|
pub fn tear_down(&self) {
|
||||||
let mut state = self.state.write();
|
let mut state = self.state.write();
|
||||||
|
|
|
@ -2117,7 +2117,7 @@ pub mod tests {
|
||||||
Self {
|
Self {
|
||||||
background,
|
background,
|
||||||
users: Default::default(),
|
users: Default::default(),
|
||||||
next_user_id: Mutex::new(1),
|
next_user_id: Mutex::new(0),
|
||||||
projects: Default::default(),
|
projects: Default::default(),
|
||||||
worktree_extensions: Default::default(),
|
worktree_extensions: Default::default(),
|
||||||
next_project_id: Mutex::new(1),
|
next_project_id: Mutex::new(1),
|
||||||
|
|
|
@ -4426,8 +4426,16 @@ async fn test_random_collaboration(
|
||||||
let mut server = TestServer::start(cx.foreground(), cx.background()).await;
|
let mut server = TestServer::start(cx.foreground(), cx.background()).await;
|
||||||
let db = server.app_state.db.clone();
|
let db = server.app_state.db.clone();
|
||||||
let host_user_id = db.create_user("host", None, false).await.unwrap();
|
let host_user_id = db.create_user("host", None, false).await.unwrap();
|
||||||
for username in ["guest-1", "guest-2", "guest-3", "guest-4"] {
|
let mut available_guests = vec![
|
||||||
|
"guest-1".to_string(),
|
||||||
|
"guest-2".to_string(),
|
||||||
|
"guest-3".to_string(),
|
||||||
|
"guest-4".to_string(),
|
||||||
|
];
|
||||||
|
|
||||||
|
for username in &available_guests {
|
||||||
let guest_user_id = db.create_user(username, None, false).await.unwrap();
|
let guest_user_id = db.create_user(username, None, false).await.unwrap();
|
||||||
|
assert_eq!(*username, format!("guest-{}", guest_user_id));
|
||||||
server
|
server
|
||||||
.app_state
|
.app_state
|
||||||
.db
|
.db
|
||||||
|
@ -4621,12 +4629,7 @@ async fn test_random_collaboration(
|
||||||
} else {
|
} else {
|
||||||
max_operations
|
max_operations
|
||||||
};
|
};
|
||||||
let mut available_guests = vec![
|
|
||||||
"guest-1".to_string(),
|
|
||||||
"guest-2".to_string(),
|
|
||||||
"guest-3".to_string(),
|
|
||||||
"guest-4".to_string(),
|
|
||||||
];
|
|
||||||
let mut operations = 0;
|
let mut operations = 0;
|
||||||
while operations < max_operations {
|
while operations < max_operations {
|
||||||
if operations == disconnect_host_at {
|
if operations == disconnect_host_at {
|
||||||
|
@ -4729,6 +4732,7 @@ async fn test_random_collaboration(
|
||||||
server.disconnect_client(removed_guest_id);
|
server.disconnect_client(removed_guest_id);
|
||||||
deterministic.advance_clock(RECEIVE_TIMEOUT);
|
deterministic.advance_clock(RECEIVE_TIMEOUT);
|
||||||
deterministic.start_waiting();
|
deterministic.start_waiting();
|
||||||
|
log::info!("Waiting for guest {} to exit...", removed_guest_id);
|
||||||
let (guest, guest_project, mut guest_cx, guest_err) = guest.await;
|
let (guest, guest_project, mut guest_cx, guest_err) = guest.await;
|
||||||
deterministic.finish_waiting();
|
deterministic.finish_waiting();
|
||||||
server.allow_connections();
|
server.allow_connections();
|
||||||
|
@ -4945,6 +4949,7 @@ impl TestServer {
|
||||||
|
|
||||||
Arc::get_mut(&mut client)
|
Arc::get_mut(&mut client)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.set_id(user_id.0 as usize)
|
||||||
.override_authenticate(move |cx| {
|
.override_authenticate(move |cx| {
|
||||||
cx.spawn(|_| async move {
|
cx.spawn(|_| async move {
|
||||||
let access_token = "the-token".to_string();
|
let access_token = "the-token".to_string();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue