diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-18 12:51:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-18 12:51:15 +0200 |
commit | db88d9e67841a287cc869ec9dd412be97d94b956 (patch) | |
tree | d048cf729416286e88ed4791bdc86c110223106f /server | |
parent | 2dfc7e9192d0c0076ba61c022d8f753469086fe0 (diff) | |
download | hurrycurry-db88d9e67841a287cc869ec9dd412be97d94b956.tar hurrycurry-db88d9e67841a287cc869ec9dd412be97d94b956.tar.bz2 hurrycurry-db88d9e67841a287cc869ec9dd412be97d94b956.tar.zst |
test server startup
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 8a54d7f3..de680200 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -242,3 +242,79 @@ async fn run(addr: SocketAddr) -> anyhow::Result<()> { } Ok(()) } + +#[cfg(test)] +mod test { + use hurrycurry_protocol::{PacketS, PlayerID}; + use hurrycurry_server::{data::DATA_DIR, server::Server, ConnectionID}; + use std::future::Future; + use tokio::sync::broadcast; + + fn harness(body: impl Future) { + *DATA_DIR.lock().unwrap() = Some("../data".into()); + tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap() + .block_on(body); + } + + #[test] + fn run() { + harness(async { Server::new(broadcast::channel(1024).0).await.unwrap() }); + } + #[test] + fn map_load() { + harness(async { + let mut s = Server::new(broadcast::channel(1024).0).await.unwrap(); + s.load(s.index.generate("lobby").await.unwrap(), None); + }); + } + #[test] + fn tick() { + harness(async { + let mut s = Server::new(broadcast::channel(1024).0).await.unwrap(); + for _ in 0..100 { + s.tick(0.1); + } + }); + } + #[test] + fn packet_sender_verif() { + harness(async { + let mut s = Server::new(broadcast::channel(1024).0).await.unwrap(); + + for (conn, p) in [ + PacketS::Effect { + player: PlayerID(0), + name: "test".to_owned(), + }, + PacketS::Leave { + player: PlayerID(0), + }, + PacketS::ReplayTick { dt: 1. }, + ] + .into_iter() + .enumerate() + { + s.packet_in_outer( + ConnectionID(conn.try_into().unwrap()), + PacketS::Join { + name: format!("test {conn}"), + character: 1, + id: None, + }, + ) + .await + .unwrap(); + assert!( + s.packet_in_outer(ConnectionID(conn.try_into().unwrap()), p) + .await + .is_err(), + "test {}", + conn, + ) + } + }); + } +} |