Skip to content

Commit

Permalink
Create integration test to check rebot command
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJacobs committed Dec 12, 2023
1 parent 7a55726 commit cc01804
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 18 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ jobs:
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- run: pip install robotframework
- uses: actions-rust-lang/[email protected]
with:
components: rustfmt, clippy
Expand Down
12 changes: 7 additions & 5 deletions v2/robotmk/src/child_process_supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::{debug, error};
use std::process::{ExitStatus, Stdio};
use std::time::Duration;
use sysinfo::{Pid, PidExt};
use tokio::process::{Child, Command};
use tokio::process::Command;
use tokio_util::sync::CancellationToken;

pub struct ChildProcessSupervisor<'a> {
Expand All @@ -22,12 +22,14 @@ pub struct StdioPaths {
pub stderr: Utf8PathBuf,
}

fn wait_for_child(
#[tokio::main]
async fn wait_for_child(
duration: Duration,
flag: &CancellationToken,
child: &mut Child,
command: &mut Command,
) -> Result<ChildProcessOutcome> {
match waited(duration, flag, child.wait()) {
let child = &mut command.spawn().context("Failed to spawn subprocess")?;
match waited(duration, flag, child.wait()).await {
Outcome::Timeout => {
error!("Timed out");
kill_child_tree(child);
Expand Down Expand Up @@ -65,7 +67,7 @@ impl ChildProcessSupervisor<'_> {
wait_for_child(
Duration::from_secs(self.timeout),
self.cancellation_token,
&mut command.spawn().context("Failed to spawn subprocess")?,
&mut command,
)
}

Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl WritePiggybackSection for SuiteExecutionReport {
}
}

#[derive(Serialize)]
#[derive(Debug, Serialize)]
pub enum AttemptOutcome {
AllTestsPassed,
TestFailures,
Expand Down
5 changes: 3 additions & 2 deletions v2/robotmk/src/sessions/schtasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use sysinfo::Pid;
use tokio::task::yield_now;
use tokio_util::sync::CancellationToken;

fn wait_for_task_exit(task: &TaskSpec, paths: &Paths) -> Result<RunOutcome> {
#[tokio::main]
async fn wait_for_task_exit(task: &TaskSpec, paths: &Paths) -> Result<RunOutcome> {
let duration = Duration::from_secs(task.timeout);
let queried = query(task.task_name, &paths.exit_code);
match waited(duration, task.cancellation_token, queried) {
match waited(duration, task.cancellation_token, queried).await {
Outcome::Cancel => {
kill_and_delete_task(task.task_name, paths);
Ok(RunOutcome::TimedOut)
Expand Down
12 changes: 4 additions & 8 deletions v2/robotmk/src/sessions/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ impl Session {

impl Display for Session {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(
f,
"{}",
match self {
Self::Current(current_session) => format!("{}", current_session),
Self::User(user_session) => format!("{}", user_session),
}
)
match self {
Self::Current(current_session) => write!(f, "{}", current_session),
Self::User(user_session) => write!(f, "{}", user_session),
}
}
}

Expand Down
1 change: 0 additions & 1 deletion v2/robotmk/src/termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub enum Outcome<T> {
Completed(T),
}

#[tokio::main]
pub async fn waited<F>(
duration: Duration,
flag: &CancellationToken,
Expand Down
32 changes: 32 additions & 0 deletions v2/robotmk/tests/test_suite_run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use anyhow::Result;
use camino::Utf8PathBuf;
use robotmk::config::RetryStrategy;
use robotmk::environment::{Environment, SystemEnvironment};
use robotmk::rf::robot::Robot;
use robotmk::sessions::session::{CurrentSession, Session};
use robotmk::suites::run_attempts_with_rebot;
use tempfile::tempdir;
use tokio_util::sync::CancellationToken;

#[test]
fn test_rebot_run() -> Result<()> {
let test_dir = Utf8PathBuf::from_path_buf(tempdir()?.into_path()).unwrap();
let robot = Robot {
robot_target: "tests/minimal_suite/tasks.robot".into(),
n_attempts_max: 1,
command_line_args: vec![],
retry_strategy: RetryStrategy::Complete,
};
let (_attempt_outcomes, rebot) = run_attempts_with_rebot(
&robot,
"test",
&Environment::System(SystemEnvironment {}),
&Session::Current(CurrentSession {}),
3,
&CancellationToken::default(),
&test_dir,
)?;
println!("{:?}", _attempt_outcomes);
assert!(rebot.is_some());
Ok(())
}
1 change: 1 addition & 0 deletions v2/robotmk/tests/timeout/minimal_suite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp/
8 changes: 8 additions & 0 deletions v2/robotmk/tests/timeout/minimal_suite/conda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
channels:
- conda-forge

dependencies:
- python=3.11.6
- pip=23.3.1
- pip:
- robotframework==6.1.1
10 changes: 10 additions & 0 deletions v2/robotmk/tests/timeout/minimal_suite/lib/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def setup() -> None:
print("Setting up...")


def teardown() -> None:
print("Tearing down...")


def add(left: int, right: int) -> int:
return left + right
12 changes: 12 additions & 0 deletions v2/robotmk/tests/timeout/minimal_suite/robot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tasks:
execute:
command:
- python
- --version

condaConfigFile: conda.yaml
artifactsDir: /tmp/outputdir # Leading slash is ignored, instead we get $(pwd)/tmp/outputdir/
PATH:
- .
PYTHONPATH:
- .
21 changes: 21 additions & 0 deletions v2/robotmk/tests/timeout/minimal_suite/tasks.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*** Settings ***
Documentation Test file for configuring RobotFramework
Library ${CURDIR}/lib/add.py WITH NAME math

Suite Setup math.setup
Suite Teardown math.teardown


*** Test Cases ***
Addition One
${result}= math.add ${20} ${5}
Should Be Equal As Integers ${result} ${25}

Addition Two
${result}= math.add ${20} ${15}
Should Be Equal As Integers ${result} ${35}

Addition Three
${result}= math.add ${20} ${25}
Should Be Equal As Integers ${result} ${45}

0 comments on commit cc01804

Please sign in to comment.