Ensure client reconnects after erroring during the handshake (#31278)
Release Notes: - Fixed a bug that prevented Zed from reconnecting after erroring during the initial handshake with the server.
This commit is contained in:
@@ -61,6 +61,35 @@ fn init_logger() {
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test(iterations = 10)]
|
||||
async fn test_database_failure_during_client_reconnection(
|
||||
executor: BackgroundExecutor,
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let mut server = TestServer::start(executor.clone()).await;
|
||||
let client = server.create_client(cx, "user_a").await;
|
||||
|
||||
// Keep disconnecting the client until a database failure prevents it from
|
||||
// reconnecting.
|
||||
server.test_db.set_query_failure_probability(0.3);
|
||||
loop {
|
||||
server.disconnect_client(client.peer_id().unwrap());
|
||||
executor.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
|
||||
if !client.status().borrow().is_connected() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the database healthy again and ensure the client can finally connect.
|
||||
server.test_db.set_query_failure_probability(0.);
|
||||
executor.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
|
||||
assert!(
|
||||
matches!(*client.status().borrow(), client::Status::Connected { .. }),
|
||||
"status was {:?}",
|
||||
*client.status().borrow()
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test(iterations = 10)]
|
||||
async fn test_basic_calls(
|
||||
executor: BackgroundExecutor,
|
||||
|
||||
@@ -52,11 +52,11 @@ use livekit_client::test::TestServer as LivekitTestServer;
|
||||
pub struct TestServer {
|
||||
pub app_state: Arc<AppState>,
|
||||
pub test_livekit_server: Arc<LivekitTestServer>,
|
||||
pub test_db: TestDb,
|
||||
server: Arc<Server>,
|
||||
next_github_user_id: i32,
|
||||
connection_killers: Arc<Mutex<HashMap<PeerId, Arc<AtomicBool>>>>,
|
||||
forbid_connections: Arc<AtomicBool>,
|
||||
_test_db: TestDb,
|
||||
}
|
||||
|
||||
pub struct TestClient {
|
||||
@@ -117,7 +117,7 @@ impl TestServer {
|
||||
connection_killers: Default::default(),
|
||||
forbid_connections: Default::default(),
|
||||
next_github_user_id: 0,
|
||||
_test_db: test_db,
|
||||
test_db,
|
||||
test_livekit_server: livekit_server,
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,12 @@ impl TestServer {
|
||||
let user = db
|
||||
.get_user_by_id(user_id)
|
||||
.await
|
||||
.expect("retrieving user failed")
|
||||
.map_err(|e| {
|
||||
EstablishConnectionError::Other(anyhow!(
|
||||
"retrieving user failed: {}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.unwrap();
|
||||
cx.background_spawn(server.handle_connection(
|
||||
server_conn,
|
||||
|
||||
Reference in New Issue
Block a user