harn-vm 0.10.180

Async bytecode virtual machine for the Harn programming language
use std::time::Duration;

use crate::VmError;

use super::tests_runtime::run_harn_result_async;

#[tokio::test(flavor = "current_thread")]
async fn parallel_settle_propagates_explicit_process_exit() {
    let local = tokio::task::LocalSet::new();
    let result = local
        .run_until(run_harn_result_async(
            r"pipeline default(harness: Harness, task: unknown) {
  const result = parallel settle [1] { _ ->
    harness.runtime.exit(7)
  }
  return result
}",
        ))
        .await;

    assert!(matches!(result, Err(VmError::ProcessExit(7))));
}

#[tokio::test(flavor = "current_thread", start_paused = true)]
async fn detached_spawn_propagates_explicit_process_exit_to_parent() {
    harn_clock::test_support::with_local_tasks(async {
        let handle = tokio::task::spawn_local(run_harn_result_async(
            r"pipeline default(harness: Harness, task: unknown) {
  const child = spawn {
    harness.runtime.exit(11)
  }
  harness.clock.sleep_ms(1000)
  return 0
}",
        ));
        tokio::task::yield_now().await;
        tokio::time::advance(Duration::from_secs(2)).await;

        let result = handle.await.expect("join VM task");
        assert!(matches!(result, Err(VmError::ProcessExit(11))));
    })
    .await;
}