This repository has been archived on 2025-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SeaBattle/rust/sea_battle_backend/src/test/random_mode.rs

40 lines
1.2 KiB
Rust

use crate::args::Args;
use crate::server::start_server;
use crate::test::bot_client::{ClientEndResult, RunMode};
use crate::test::{bot_client, TestPort};
use crate::utils::network_utils::wait_for_port;
use std::error::Error;
use tokio::task;
async fn play_random(port: TestPort) -> Result<ClientEndResult, Box<dyn Error>> {
bot_client::BotClient::new(port.as_url())
.with_run_mode(RunMode::Random)
.run_client()
.await
}
#[tokio::test]
async fn four_games() {
let _ = env_logger::builder().is_test(true).try_init();
let local_set = task::LocalSet::new();
local_set
.run_until(async move {
task::spawn_local(start_server(Args::for_test(TestPort::RandomModeFourGames)));
wait_for_port(TestPort::RandomModeFourGames.port()).await;
let mut fut = vec![];
for _ in 0..4 {
fut.push(task::spawn_local(play_random(
TestPort::RandomModeFourGames,
)));
}
for handle in fut {
let res = handle.await.unwrap().unwrap();
assert!(matches!(res, ClientEndResult::Finished { .. }));
}
})
.await;
}