diff --git a/crates/arc-workflows/tests/daytona_integration.rs b/crates/arc-workflows/tests/daytona_integration.rs index cfba4c48a..96a8b6683 100644 --- a/crates/arc-workflows/tests/daytona_integration.rs +++ b/crates/arc-workflows/tests/daytona_integration.rs @@ -108,6 +108,64 @@ async fn daytona_exec_command_with_pipe() { env.cleanup().await.unwrap(); } +#[tokio::test] +#[ignore] +async fn daytona_exec_command_cancelled() { + let env = create_env().await; + env.initialize().await.unwrap(); + + let token = tokio_util::sync::CancellationToken::new(); + let token_clone = token.clone(); + + // Cancel the token shortly after starting + tokio::spawn(async move { + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + token_clone.cancel(); + }); + + // Execute a command that would normally take a while + let result = env + .exec_command("sleep 10", 30_000, None, None, Some(token)) + .await + .unwrap(); + + assert_eq!(result.exit_code, -1); + assert!(result.timed_out); + assert_eq!(result.stderr, "Command cancelled"); + + env.cleanup().await.unwrap(); +} + +#[tokio::test] +#[ignore] +async fn daytona_exec_command_local_timeout() { + let env = create_env().await; + env.initialize().await.unwrap(); + + // Use a tiny timeout_ms of 100ms, our local timeout is 100 + 5000 = 5100ms. + // If the server doesn't enforce the timeout properly or drops the connection, + // our local timeout should catch it. To simulate this without making a bad server, + // we can't easily force the local timeout to hit before the server timeout + // without mocking. But if we run `sleep 10` and Daytona does NOT respect the + // short timeout parameter, the local 5.1s timeout will definitely fire. + // Let's at least test that a 100ms timeout works and doesn't run for 10s. + let start = std::time::Instant::now(); + let result = env + .exec_command("sleep 10", 100, None, None, None) + .await + .unwrap(); + + let duration = start.elapsed(); + + // It should either fail with Daytona's timeout (duration < 5000ms) or our + // local timeout (duration ~5100ms). Both are valid success conditions for + // the system as a whole avoiding a stall. + assert!(duration < std::time::Duration::from_millis(6000), "Command stalled for longer than the local timeout mechanism"); + assert!(result.exit_code != 0); + + env.cleanup().await.unwrap(); +} + #[tokio::test] #[ignore] async fn daytona_file_round_trip() {