Skip to content

Commit

Permalink
Add timeout to repl test wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelazaroff committed Jan 28, 2025
1 parent 76b93dd commit d0107e8
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions rust/forevervm-sdk/tests/basic_sdk_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use forevervm_sdk::{
client::ForeverVMClient,
};
use std::env;
use tokio::time::{timeout, Duration};
use url::Url;

fn get_test_credentials() -> (Url, ApiToken) {
Expand Down Expand Up @@ -86,35 +87,40 @@ async fn test_exec() {

#[tokio::test]
async fn test_repl() {
let (api_base, token) = get_test_credentials();
let client = ForeverVMClient::new(api_base, token);
let result = timeout(Duration::from_millis(20_000), async {
let (api_base, token) = get_test_credentials();
let client = ForeverVMClient::new(api_base, token);

// Create machine and get REPL
let machine = client
.create_machine()
.await
.expect("failed to create machine");
let mut repl = client
.repl(&machine.machine_name)
.await
.expect("failed to create REPL");
assert_eq!(repl.machine_name, machine.machine_name);
// Create machine and get REPL
let machine = client
.create_machine()
.await
.expect("failed to create machine");
let mut repl = client
.repl(&machine.machine_name)
.await
.expect("failed to create REPL");
assert_eq!(repl.machine_name, machine.machine_name);

// Execute code that produces multiple outputs
let code = "for i in range(5):\n print(i)";
let mut result = repl.exec(code).await.expect("failed to execute code");
// Execute code that produces multiple outputs
let code = "for i in range(5):\n print(i)";
let mut result = repl.exec(code).await.expect("failed to execute code");

// Collect all output
let mut outputs = Vec::new();
while let Some(output) = result.next().await {
outputs.push(output);
}
// Collect all output
let mut outputs = Vec::new();
while let Some(output) = result.next().await {
outputs.push(output);
}

// Verify outputs
assert_eq!(outputs.len(), 5);
for (i, output) in outputs.iter().enumerate() {
assert_eq!(output.stream, StandardOutputStream::Stdout);
assert_eq!(output.data, i.to_string());
assert_eq!(output.seq, (i as i64).into());
}
})
.await;

// Verify outputs
assert_eq!(outputs.len(), 5);
for (i, output) in outputs.iter().enumerate() {
assert_eq!(output.stream, StandardOutputStream::Stdout);
assert_eq!(output.data, i.to_string());
assert_eq!(output.seq, (i as i64).into());
}
assert!(result.is_ok(), "Test timed out");
}

0 comments on commit d0107e8

Please sign in to comment.