Start local server on client run
This commit is contained in:
@ -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,25 +0,0 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use tokio::net::TcpStream;
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
/// Wait for a port to become available
|
||||
pub async fn wait_for_port(port: u16) {
|
||||
for _ in 0..50 {
|
||||
if is_port_open(port).await {
|
||||
return;
|
||||
}
|
||||
time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
|
||||
eprintln!("Port {} did not open in time!", port);
|
||||
std::process::exit(2);
|
||||
}
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user