Start local server on client run
This commit is contained in:
		@@ -11,7 +11,7 @@ use crate::consts::INVITE_CODE_LENGTH;
 | 
			
		||||
use crate::data::GameRules;
 | 
			
		||||
use crate::game::Game;
 | 
			
		||||
use crate::human_player_ws::{CloseConnection, HumanPlayerWS, ServerMessage, SetGame};
 | 
			
		||||
use crate::utils::rand_str;
 | 
			
		||||
use crate::utils::string_utils::rand_str;
 | 
			
		||||
 | 
			
		||||
/// How often garbage collector is run
 | 
			
		||||
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(60);
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,8 @@ use crate::data::{BotType, CurrentGameStatus, GameRules};
 | 
			
		||||
use crate::human_player_ws::ServerMessage;
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client::ClientEndResult;
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::{bot_client, TestPort};
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
 | 
			
		||||
#[tokio::test]
 | 
			
		||||
async fn full_game() {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@ use crate::data::{BoatsLayout, BotType, Coordinates, GameRules};
 | 
			
		||||
use crate::human_player_ws::ServerMessage;
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client::ClientEndResult;
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::play_utils::check_no_replay_on_hit;
 | 
			
		||||
use crate::test::{bot_client, TestPort};
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
 | 
			
		||||
fn check_strikes_are_linear(msg: &ServerMessage) {
 | 
			
		||||
    if let ServerMessage::RequestFire { status } = msg {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@ use crate::data::{BoatsLayout, GameRules};
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client;
 | 
			
		||||
use crate::test::bot_client::ClientEndResult;
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::play_utils::check_no_replay_on_hit;
 | 
			
		||||
use crate::test::TestPort;
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
 | 
			
		||||
#[tokio::test]
 | 
			
		||||
async fn invalid_port() {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,8 +5,8 @@ use crate::data::{BotType, CurrentGameStatus, GameRules};
 | 
			
		||||
use crate::human_player_ws::ServerMessage;
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client::ClientEndResult;
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::{bot_client, TestPort};
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
 | 
			
		||||
#[tokio::test]
 | 
			
		||||
async fn full_game() {
 | 
			
		||||
 
 | 
			
		||||
@@ -9,8 +9,8 @@ use crate::data::BotType;
 | 
			
		||||
use crate::human_player_ws::ServerMessage;
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client::{ClientEndResult, RunMode};
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::{bot_client, TestPort};
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
 | 
			
		||||
#[tokio::test]
 | 
			
		||||
async fn invalid_accept_code() {
 | 
			
		||||
 
 | 
			
		||||
@@ -46,6 +46,5 @@ mod bot_linear_play;
 | 
			
		||||
mod bot_random_play;
 | 
			
		||||
mod bot_smart_play;
 | 
			
		||||
mod invite_mode;
 | 
			
		||||
mod network_utils;
 | 
			
		||||
mod play_utils;
 | 
			
		||||
mod random_mode;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
use crate::args::Args;
 | 
			
		||||
use crate::server::start_server;
 | 
			
		||||
use crate::test::bot_client::{ClientEndResult, RunMode};
 | 
			
		||||
use crate::test::network_utils::wait_for_port;
 | 
			
		||||
use crate::test::{bot_client, TestPort};
 | 
			
		||||
use crate::utils::network_utils::wait_for_port;
 | 
			
		||||
use std::error::Error;
 | 
			
		||||
use tokio::task;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								rust/sea_battle_backend/src/utils/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								rust/sea_battle_backend/src/utils/mod.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
pub mod network_utils;
 | 
			
		||||
pub mod string_utils;
 | 
			
		||||
@@ -5,10 +5,7 @@ use tokio::time;
 | 
			
		||||
 | 
			
		||||
/// Check whether a given port is open or not
 | 
			
		||||
pub async fn is_port_open(port: u16) -> bool {
 | 
			
		||||
    match TcpStream::connect(("127.0.0.1", port)).await {
 | 
			
		||||
        Ok(_) => true,
 | 
			
		||||
        Err(_) => false,
 | 
			
		||||
    }
 | 
			
		||||
    TcpStream::connect(("127.0.0.1", port)).await.is_ok()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Wait for a port to become available
 | 
			
		||||
@@ -12,7 +12,7 @@ pub fn rand_str(len: usize) -> String {
 | 
			
		||||
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod test {
 | 
			
		||||
    use crate::utils::rand_str;
 | 
			
		||||
    use crate::utils::string_utils::rand_str;
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_rand_str() {
 | 
			
		||||
		Reference in New Issue
	
	Block a user