//! WebSocket service tests //! //! Note: These tests are currently stubbed out as the WebSocket implementation //! does not provide the full API being tested here. Future work should implement //! the complete WebSocket server and connection management. #[cfg(test)] mod tests { use rtx_serving_api::websocket::{ WebSocketConfig, WebSocketMessage, WebSocketRequest, WebSocketResponse, }; #[tokio::test] async fn test_websocket_config_creation() { let config = WebSocketConfig::default(); assert_eq!(config.port, 8080); assert_eq!(config.max_connections, 1000); assert_eq!(config.heartbeat_interval, 30); } #[tokio::test] async fn test_websocket_config_mutation() { let mut config = WebSocketConfig::default(); config.set_max_connections(2); config.set_heartbeat_interval(10); assert_eq!(config.max_connections, 2); assert_eq!(config.heartbeat_interval, 10); } #[test] fn test_websocket_message_types() { let ping = WebSocketMessage::Ping(vec![1, 2, 3]); let pong = WebSocketMessage::Pong(vec![1, 2, 3]); let heartbeat = WebSocketMessage::Heartbeat(12345); let text = WebSocketMessage::Text("hello".to_string()); let close = WebSocketMessage::Close; // Verify they can be created assert!(matches!(ping, WebSocketMessage::Ping(_))); assert!(matches!(pong, WebSocketMessage::Pong(_))); assert!(matches!(heartbeat, WebSocketMessage::Heartbeat(_))); assert!(matches!(text, WebSocketMessage::Text(_))); assert!(matches!(close, WebSocketMessage::Close)); } #[test] fn test_websocket_request_types() { let inference_req = WebSocketRequest::Inference { model_name: "test-model".to_string(), input_data: vec![1.0, 2.0, 3.0], stream: false, }; let model_info_req = WebSocketRequest::ModelInfo { model_name: "test-model".to_string(), }; // Verify they can be created assert!(matches!(inference_req, WebSocketRequest::Inference { .. })); assert!(matches!(model_info_req, WebSocketRequest::ModelInfo { .. })); } #[test] fn test_websocket_response_types() { let inference_resp = WebSocketResponse::InferenceResult { model_name: "test-model".to_string(), outputs: vec![0.5, 0.3, 0.2], latency_ms: 10.5, }; let error_resp = WebSocketResponse::Error { message: "Model not found".to_string(), code: 404, }; // Verify they can be created assert!(matches!( inference_resp, WebSocketResponse::InferenceResult { .. } )); assert!(matches!(error_resp, WebSocketResponse::Error { .. })); } #[test] fn test_websocket_message_equality() { let ping1 = WebSocketMessage::Ping(vec![1, 2, 3]); let ping2 = WebSocketMessage::Ping(vec![1, 2, 3]); let ping3 = WebSocketMessage::Ping(vec![4, 5, 6]); assert_eq!(ping1, ping2); assert_ne!(ping1, ping3); } }