From 41e860f0321955830f0c8b3cf2d316e4765e23a4 Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Sun, 4 Oct 2026 19:39:44 -0700 Subject: [PATCH] cleanup: remove PlayerTracking from the Rust SDK Remove the PlayerTracking methods from the Rust SDK while keeping the Alpha client as a stub for future alpha features, following the same approach as the Python and Node.js SDK removals. - Remove the seven player-tracking methods (get_player_capacity, set_player_capacity, player_connect, player_disconnect, get_player_count, is_player_connected, get_connected_players) from src/alpha.rs, leaving the gRPC client stub in place. - Replace the player tracking unit tests (a hand-rolled MockAlpha and its lifecycle test) with a stub test that verifies the Alpha client's gRPC channel is constructed. - Remove the player tracking steps (and their now-unused functions) from the Rust SDK conformance test client, for both the sync and async code paths. Work on #4491 Signed-off-by: Mark Mandel --- sdks/rust/src/alpha.rs | 207 +++----------------------------------- test/sdk/rust/src/main.rs | 161 ----------------------------- 2 files changed, 12 insertions(+), 356 deletions(-) diff --git a/sdks/rust/src/alpha.rs b/sdks/rust/src/alpha.rs index b698e92a2c..3003429f76 100644 --- a/sdks/rust/src/alpha.rs +++ b/sdks/rust/src/alpha.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::errors::Result; use tonic::transport::Channel; mod api { @@ -24,6 +23,9 @@ use api::sdk_client::SdkClient; /// Alpha is an instance of the Agones Alpha SDK #[derive(Clone)] pub struct Alpha { + // Not currently used by any method, but kept for future Alpha SDK + // features. + #[allow(dead_code)] client: SdkClient, } @@ -34,206 +36,21 @@ impl Alpha { client: SdkClient::new(ch), } } - - /// This returns the last player capacity that was set through the SDK. - /// If the player capacity is set from outside the SDK, use - /// [`Sdk::get_gameserver`] instead. - #[inline] - pub async fn get_player_capacity(&mut self) -> Result { - Ok(self - .client - .get_player_capacity(api::Empty {}) - .await - .map(|c| c.into_inner().count)?) - } - - /// This changes the player capacity to a new value. - #[inline] - pub async fn set_player_capacity(&mut self, count: i64) -> Result<()> { - Ok(self - .client - .set_player_capacity(api::Count { count }) - .await - .map(|_| ())?) - } - - /// This function increases the SDK’s stored player count by one, and appends - /// this playerID to `GameServer.status.players.ids`. - /// - /// Returns true and adds the playerID to the list of playerIDs if the - /// playerIDs was not already in the list of connected playerIDs. - #[inline] - pub async fn player_connect(&mut self, id: impl Into) -> Result { - Ok(self - .client - .player_connect(api::PlayerId { - player_id: id.into(), - }) - .await - .map(|b| b.into_inner().bool)?) - } - - /// This function decreases the SDK’s stored player count by one, and removes - /// the playerID from GameServer.status.players.ids. - /// - /// Will return true and remove the supplied playerID from the list of - /// connected playerIDs if the playerID value exists within the list. - #[inline] - pub async fn player_disconnect(&mut self, id: impl Into) -> Result { - Ok(self - .client - .player_disconnect(api::PlayerId { - player_id: id.into(), - }) - .await - .map(|b| b.into_inner().bool)?) - } - - /// Returns the current player count. - #[inline] - pub async fn get_player_count(&mut self) -> Result { - Ok(self - .client - .get_player_count(api::Empty {}) - .await - .map(|c| c.into_inner().count)?) - } - - /// This returns if the playerID is currently connected to the GameServer. - /// This is always accurate, even if the value hasn’t been updated to the - /// Game Server status yet. - #[inline] - pub async fn is_player_connected(&mut self, id: impl Into) -> Result { - Ok(self - .client - .is_player_connected(api::PlayerId { - player_id: id.into(), - }) - .await - .map(|b| b.into_inner().bool)?) - } - - /// This returns the list of the currently connected player ids. - /// This is always accurate, even if the value has not been updated to the - /// Game Server status yet. - #[inline] - pub async fn get_connected_players(&mut self) -> Result> { - Ok(self - .client - .get_connected_players(api::Empty {}) - .await - .map(|pl| pl.into_inner().list)?) - } } #[cfg(test)] mod tests { - use tokio; - - // MockAlpha simulates Alpha's async methods for unit testing - struct MockAlpha { - capacity: i64, - player_count: i64, - player_connected: Option, - player_disconnected: Option, - } - - impl MockAlpha { - fn new() -> Self { - Self { - capacity: 0, - player_count: 0, - player_connected: None, - player_disconnected: None, - } - } - - async fn get_player_capacity(&mut self) -> i64 { - self.capacity - } - - async fn set_player_capacity(&mut self, count: i64) { - self.capacity = count; - } - - async fn player_connect(&mut self, id: impl Into) -> bool { - let id = id.into(); - self.player_connected = Some(id.clone()); - self.player_count += 1; - true - } - - async fn player_disconnect(&mut self, id: impl Into) -> bool { - let id = id.into(); - self.player_disconnected = Some(id.clone()); - if self.player_count > 0 { - self.player_count -= 1; - } - true - } - - async fn get_player_count(&mut self) -> i64 { - self.player_count - } - - async fn is_player_connected(&mut self, id: impl Into) -> bool { - match &self.player_connected { - Some(connected) => id.into() == *connected, - None => false, - } - } - - async fn get_connected_players(&mut self) -> Vec { - match &self.player_connected { - Some(id) => vec![id.clone()], - None => vec![], - } - } - } + use super::*; #[tokio::test] - async fn test_alpha_player_flow() { - let mut alpha = MockAlpha::new(); - - // Set and get player capacity - alpha.set_player_capacity(15).await; - assert_eq!(alpha.capacity, 15); - - let capacity = alpha.get_player_capacity().await; - assert_eq!(capacity, 15); - - // Connect player - let player_id = "one"; - let ok = alpha.player_connect(player_id).await; - assert!(ok); - assert_eq!(alpha.player_connected.as_deref(), Some(player_id)); - - // Get player count - let count = alpha.get_player_count().await; - assert_eq!(count, 1); - - // Disconnect player - let ok = alpha.player_disconnect(player_id).await; - assert!(ok); - assert_eq!(alpha.player_disconnected.as_deref(), Some(player_id)); - - // Put the player back in - let ok = alpha.player_connect(player_id).await; - assert!(ok); - let count = alpha.get_player_count().await; - assert_eq!(count, 1); - - // Is player connected (should be true) - let ok = alpha.is_player_connected(player_id).await; - assert!(ok, "Player should be connected"); - - // Is player connected (should be false) - let ok = alpha.is_player_connected("false").await; - assert!(!ok, "Player should not be connected"); - - // Get connected players - let list = alpha.get_connected_players().await; - assert_eq!(list, vec![player_id]); + async fn test_new() { + // connect_lazy() defers the actual connection until first use, so + // this doesn't require a running server (sdk.rs uses the same + // pattern to build its own client), but it still needs a Tokio + // runtime in context. + let channel = Channel::from_static("http://[::1]:9357").connect_lazy(); + let alpha = Alpha::new(channel); + let _client = alpha.client; } } \ No newline at end of file diff --git a/test/sdk/rust/src/main.rs b/test/sdk/rust/src/main.rs index 1d69703bb3..0b40d4056d 100644 --- a/test/sdk/rust/src/main.rs +++ b/test/sdk/rust/src/main.rs @@ -181,9 +181,6 @@ fn run_sync() -> Result<(), String> { })?; let feature_gates = env::var("FEATURE_GATES").unwrap_or_default(); - if feature_gates.contains("PlayerTracking=true") { - run_player_tracking_features(sdk.alpha().clone())?; - } if feature_gates.contains("CountsAndLists=true") { run_counts_and_lists_features(sdk.beta().clone())?; } @@ -206,93 +203,6 @@ fn run_sync() -> Result<(), String> { Ok(()) } -fn run_player_tracking_features(mut alpha: agones::alpha::Alpha) -> Result<(), String> { - use tokio::runtime::Handle; - - println!("rust: Setting player capacity..."); - Handle::current().block_on(async { - alpha - .set_player_capacity(10) - .await - .map_err(|e| format!("Could not run SetPlayerCapacity(): {:#?}. Exiting!", e)) - })?; - - println!("rust: Getting player capacity..."); - let capacity = Handle::current().block_on(async { - alpha - .get_player_capacity() - .await - .map_err(|e| format!("Could not run GetPlayerCapacity(): {}. Exiting!", e)) - })?; - println!("rust: Player capacity: {}", capacity); - - println!("rust: Increasing the player count..."); - let player_id = "1234".to_string(); - - let added = Handle::current().block_on(async { - alpha - .player_connect(&player_id) - .await - .map_err(|e| format!("Could not run PlayerConnect(): {}. Exiting!", e)) - })?; - if added { - println!("rust: Added player"); - } else { - panic!("rust: Failed to add player. Exiting!"); - } - - let connected = Handle::current().block_on(async { - alpha - .is_player_connected(&player_id) - .await - .map_err(|e| format!("Could not run IsPlayerConnected(): {}. Exiting!", e)) - })?; - if connected { - println!("rust: {} is connected", player_id); - } else { - panic!("rust: {} is not connected. Exiting!", player_id); - } - - let player_ids = Handle::current().block_on(async { - alpha - .get_connected_players() - .await - .map_err(|e| format!("Could not run GetConnectedPlayers(): {}. Exiting!", e)) - })?; - println!("rust: Connected players: {:?}", player_ids); - - let player_count = Handle::current().block_on(async { - alpha - .get_player_count() - .await - .map_err(|e| format!("Could not run GetConnectedPlayers(): {}. Exiting!", e)) - })?; - println!("rust: Current player count: {}", player_count); - - println!("rust: Decreasing the player count..."); - let removed = Handle::current().block_on(async { - alpha - .player_disconnect(&player_id) - .await - .map_err(|e| format!("Could not run PlayerDisconnect(): {}. Exiting!", e)) - })?; - if removed { - println!("rust: Removed player"); - } else { - panic!("rust: Failed to remove player. Exiting!"); - } - - let player_count = Handle::current().block_on(async { - alpha - .get_player_count() - .await - .map_err(|e| format!("Could not GetPlayerCount(): {}. Exiting!", e)) - })?; - println!("rust: Current player count: {}", player_count); - - Ok(()) -} - fn run_counts_and_lists_features(mut beta: agones::beta::Beta) -> Result<(), String> { use tokio::runtime::Handle; @@ -529,9 +439,6 @@ async fn run_async() -> Result<(), String> { .map_err(|e| format!("Could not run SetLabel(): {}. Exiting!", e))?; let feature_gates = env::var("FEATURE_GATES").unwrap_or_default(); - if feature_gates.contains("PlayerTracking=true") { - run_player_tracking_features_async(sdk.alpha().clone()).await?; - } if feature_gates.contains("CountsAndLists=true") { run_counts_and_lists_features_async(sdk.beta().clone()).await?; } @@ -552,74 +459,6 @@ async fn run_async() -> Result<(), String> { Ok(()) } -async fn run_player_tracking_features_async(mut alpha: agones::alpha::Alpha) -> Result<(), String> { - println!("rust_async: Setting player capacity..."); - alpha - .set_player_capacity(10) - .await - .map_err(|e| format!("Could not run SetPlayerCapacity(): {}. Exiting!", e))?; - - println!("rust_async: Getting player capacity..."); - let capacity = alpha - .get_player_capacity() - .await - .map_err(|e| format!("Could not run GetPlayerCapacity(): {}. Exiting!", e))?; - println!("rust_async: Player capacity: {}", capacity); - - println!("rust_async: Increasing the player count..."); - let player_id = "1234".to_string(); - let added = alpha - .player_connect(&player_id) - .await - .map_err(|e| format!("Could not run PlayerConnect(): {}. Exiting!", e))?; - if added { - println!("Added player"); - } else { - panic!("rust_async: Failed to add player. Exiting!"); - } - - let connected = alpha - .is_player_connected(&player_id) - .await - .map_err(|e| format!("Could not run IsPlayerConnected(): {}. Exiting!", e))?; - if connected { - println!("rust_async: {} is connected", player_id); - } else { - panic!("rust_async: {} is not connected. Exiting!", player_id); - } - - let player_ids = alpha - .get_connected_players() - .await - .map_err(|e| format!("Could not run GetConnectedPlayers(): {}. Exiting!", e))?; - println!("rust_async: Connected players: {:?}", player_ids); - - let player_count = alpha - .get_player_count() - .await - .map_err(|e| format!("Could not run GetConnectedPlayers(): {}. Exiting!", e))?; - println!("rust_async: Current player count: {}", player_count); - - println!("rust_async: Decreasing the player count..."); - let removed = alpha - .player_disconnect(&player_id) - .await - .map_err(|e| format!("Could not run PlayerDisconnect(): {}. Exiting!", e))?; - if removed { - println!("rust_async: Removed player"); - } else { - panic!("rust_async: Failed to remove player. Exiting!"); - } - - let player_count = alpha - .get_player_count() - .await - .map_err(|e| format!("Could not GetPlayerCount(): {}. Exiting!", e))?; - println!("rust_async: Current player count: {}", player_count); - - Ok(()) -} - async fn run_counts_and_lists_features_async(mut beta: agones::beta::Beta) -> Result<(), String> { // Counter tests let counter = "rooms";