From fa5a5fa200ce75f2979579ec255ab12332eb652d Mon Sep 17 00:00:00 2001 From: Stuart Axelbrooke Date: Tue, 14 Oct 2025 20:08:35 -0700 Subject: [PATCH] integrate test bin and get failing first job run test --- databuild/BUILD.bazel | 1 + databuild/job_run.rs | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/databuild/BUILD.bazel b/databuild/BUILD.bazel index b94fafe..d5b269b 100644 --- a/databuild/BUILD.bazel +++ b/databuild/BUILD.bazel @@ -39,6 +39,7 @@ rust_library( rust_test( name = "databuild_test", crate = ":databuild", + data = ["//databuild/test:test_job_helper"], ) # Legacy filegroup for backwards compatibility diff --git a/databuild/job_run.rs b/databuild/job_run.rs index 01adeeb..ea1965f 100644 --- a/databuild/job_run.rs +++ b/databuild/job_run.rs @@ -82,20 +82,65 @@ pub struct JobRunPollResult { } mod tests { + use crate::JobRunStatusCode; + /// Happy path - run that succeeds should emit a JobRunSuccessEventV1 #[test] + #[ignore] fn test_job_run_success_returns_job_run_success_event() { - todo!() + use super::*; + use crate::data_build_event::Event; + + // Get path to test helper binary from Bazel runfiles + let test_helper = std::env::var("TEST_SRCDIR") + .map(|srcdir| format!("{}/_main/databuild/test/test_job_helper", srcdir)) + .unwrap_or_else(|_| "bazel-bin/databuild/test/test_job_helper".to_string()); + + println!("test_helper: {}", test_helper); + + // Spawn a job run that will succeed (exit code 0) + let mut job_run = SubProcessJobRun::spawn(test_helper, vec![]).unwrap(); + + // Start the job + job_run.run().unwrap(); + + // Poll until we get completion + loop { + let result = job_run.visit().unwrap(); + + // Check if we got a success event + let has_success = result.new_events.iter().any(|event| { + matches!(event, Event::JobRunSuccessV1(_)) + }); + + if has_success { + let expected = JobRunStatusCode::JobRunSucceeded as i32; + assert!(matches!(result.status.code, expected)); + break; + } + + // If job is still running, sleep briefly and poll again + let expected = JobRunStatusCode::JobRunRunning as i32; + if matches!(result.status.code, expected) { + std::thread::sleep(std::time::Duration::from_millis(10)); + continue; + } + + // If we got here, job failed when it shouldn't have + panic!("Job failed unexpectedly: {:?}", result.status); + } } /// Job that runs for more than 1 heartbeat interval should emit a JobRunHeartbeatEventV1 event #[test] + #[ignore] fn test_running_job_run_poll_returns_heartbeat() { todo!() } /// Job run that fails should emit a JobRunFailureEventV1 #[test] + #[ignore] fn test_job_run_failure_returns_job_run_failure_event() { todo!() } @@ -104,6 +149,7 @@ mod tests { /// - Stop the actual subprocess (e.g. no output file should be written) /// - Emitting a JobRunCancelEventV1 event #[test] + #[ignore] fn test_job_run_cancel_returns_job_run_cancel_event() { todo!() }