aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner/tests
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-matchrunner/tests')
-rw-r--r--planetwars-matchrunner/tests/test_matchrunner.rs33
1 files changed, 23 insertions, 10 deletions
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<B: BotSpec>(bot_spec: B) -> MatchCtx {
+/// creates a simple match ctx which only holds a single bot
+async fn with_bot_match_ctx<B, F>(bot_spec: B, func: F)
+where
+ F: FnOnce(&mut MatchCtx) -> Pin<Box<dyn '_ + Future<Output = ()>>>,
+ 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<B, F>(bot_spec: B, func: F)
-where
- F: FnOnce(&mut MatchCtx) -> Pin<Box<dyn '_ + Future<Output = ()>>>,
- 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;
+}