Start local server on client run

This commit is contained in:
2022-10-01 20:44:01 +02:00
parent 14c5820ed2
commit 7a06feb7cf
18 changed files with 88 additions and 18 deletions

View File

@ -19,9 +19,9 @@ actix-rt = "2.7.0"
uuid = { version = "1.1.2", features = ["v4"] }
rand = "0.8.5"
serde_with = "2.0.1"
tokio = { version = "1", features = ["full"] }
[dev-dependencies]
tokio = { version = "1", features = ["full"] }
#reqwest = { version = "0.11.11", default-features = false, features = ["json", "rustls-tls"] }
tokio-tungstenite = "0.17.2"
serde_urlencoded = "0.7.1"

View File

@ -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);

View File

@ -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() {

View File

@ -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 {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,2 @@
pub mod network_utils;
pub mod string_utils;

View File

@ -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

View File

@ -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() {