From f7261e165bda87dae49c879bdac850479cc20c19 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 24 Sep 2022 23:37:23 +0200 Subject: detect bot crashes --- planetwars-matchrunner/tests/test_matchrunner.rs | 33 +++++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'planetwars-matchrunner/tests/test_matchrunner.rs') diff --git a/planetwars-matchrunner/tests/test_matchrunner.rs b/planetwars-matchrunner/tests/test_matchrunner.rs index 131a7b8..caa78c0 100644 --- a/planetwars-matchrunner/tests/test_matchrunner.rs +++ b/planetwars-matchrunner/tests/test_matchrunner.rs @@ -56,23 +56,20 @@ async fn match_does_run() { tokio::time::sleep(Duration::from_secs(1)).await } -async fn match_ctx_from_bot_spec(bot_spec: B) -> MatchCtx { +/// creates a simple match ctx which only holds a single bot +async fn with_bot_match_ctx(bot_spec: B, func: F) +where + F: FnOnce(&mut MatchCtx) -> Pin>>, + B: BotSpec, +{ let event_bus = Arc::new(Mutex::new(EventBus::new())); let (logger, _rx) = mpsc::unbounded_channel(); let player_handle = bot_spec.run_bot(1, event_bus.clone(), logger.clone()).await; let mut players = HashMap::new(); players.insert(1, player_handle); - MatchCtx::new(event_bus, players, logger) -} + let mut ctx = MatchCtx::new(event_bus, players, logger); -/// creates a simple match ctx which only holds a single bot -async fn with_bot_match_ctx(bot_spec: B, func: F) -where - F: FnOnce(&mut MatchCtx) -> Pin>>, - B: BotSpec, -{ - let mut ctx = match_ctx_from_bot_spec(bot_spec).await; func(&mut ctx).await; ctx.shutdown().await; } @@ -108,3 +105,19 @@ async fn docker_runner_timeout() { }) .await; } + +#[tokio::test] +async fn docker_runner_crash() { + let bot_spec = simple_python_docker_bot_spec("./bots", "crash_bot.py"); + with_bot_match_ctx(bot_spec, |ctx| { + async move { + let resp = ctx + .request(1, b"sup".to_vec(), Duration::from_millis(200)) + .await; + + assert_eq!(resp, Err(RequestError::BotTerminated)); + } + .boxed() + }) + .await; +} -- cgit v1.2.3