integrate test bin and get failing first job run test
This commit is contained in:
parent
d7fb2323d8
commit
fa5a5fa200
2 changed files with 48 additions and 1 deletions
|
|
@ -39,6 +39,7 @@ rust_library(
|
||||||
rust_test(
|
rust_test(
|
||||||
name = "databuild_test",
|
name = "databuild_test",
|
||||||
crate = ":databuild",
|
crate = ":databuild",
|
||||||
|
data = ["//databuild/test:test_job_helper"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Legacy filegroup for backwards compatibility
|
# Legacy filegroup for backwards compatibility
|
||||||
|
|
|
||||||
|
|
@ -82,20 +82,65 @@ pub struct JobRunPollResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::JobRunStatusCode;
|
||||||
|
|
||||||
/// Happy path - run that succeeds should emit a JobRunSuccessEventV1
|
/// Happy path - run that succeeds should emit a JobRunSuccessEventV1
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_job_run_success_returns_job_run_success_event() {
|
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
|
/// Job that runs for more than 1 heartbeat interval should emit a JobRunHeartbeatEventV1 event
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_running_job_run_poll_returns_heartbeat() {
|
fn test_running_job_run_poll_returns_heartbeat() {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Job run that fails should emit a JobRunFailureEventV1
|
/// Job run that fails should emit a JobRunFailureEventV1
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_job_run_failure_returns_job_run_failure_event() {
|
fn test_job_run_failure_returns_job_run_failure_event() {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +149,7 @@ mod tests {
|
||||||
/// - Stop the actual subprocess (e.g. no output file should be written)
|
/// - Stop the actual subprocess (e.g. no output file should be written)
|
||||||
/// - Emitting a JobRunCancelEventV1 event
|
/// - Emitting a JobRunCancelEventV1 event
|
||||||
#[test]
|
#[test]
|
||||||
|
#[ignore]
|
||||||
fn test_job_run_cancel_returns_job_run_cancel_event() {
|
fn test_job_run_cancel_returns_job_run_cancel_event() {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue