Implement tests for want grouping and impl job configuration matching
This commit is contained in:
parent
97ddb3ae28
commit
9342ae6816
5 changed files with 739 additions and 595 deletions
|
|
@ -148,6 +148,10 @@ crate.spec(
|
||||||
package = "chrono",
|
package = "chrono",
|
||||||
version = "0.4",
|
version = "0.4",
|
||||||
)
|
)
|
||||||
|
crate.spec(
|
||||||
|
package = "regex",
|
||||||
|
version = "1.10",
|
||||||
|
)
|
||||||
crate.from_specs()
|
crate.from_specs()
|
||||||
use_repo(crate, "crates")
|
use_repo(crate, "crates")
|
||||||
|
|
||||||
|
|
|
||||||
1236
MODULE.bazel.lock
1236
MODULE.bazel.lock
File diff suppressed because one or more lines are too long
|
|
@ -40,6 +40,7 @@ rust_library(
|
||||||
"@crates//:log",
|
"@crates//:log",
|
||||||
"@crates//:prost",
|
"@crates//:prost",
|
||||||
"@crates//:prost-types",
|
"@crates//:prost-types",
|
||||||
|
"@crates//:regex",
|
||||||
"@crates//:rusqlite",
|
"@crates//:rusqlite",
|
||||||
"@crates//:schemars",
|
"@crates//:schemars",
|
||||||
"@crates//:serde",
|
"@crates//:serde",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use regex::Regex;
|
||||||
use crate::job_run::JobRun;
|
use crate::job_run::JobRun;
|
||||||
use crate::{PartitionRef, WantDetail};
|
use crate::{PartitionRef, WantDetail};
|
||||||
|
|
||||||
|
|
@ -19,6 +20,8 @@ impl JobConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn matches(&self, refs: &PartitionRef) -> bool {
|
pub fn matches(&self, refs: &PartitionRef) -> bool {
|
||||||
todo!()
|
let regex = Regex::new(&self.pattern)
|
||||||
|
.expect(&format!("Invalid regex pattern: {}", self.pattern));
|
||||||
|
regex.is_match(&refs.r#ref)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,94 @@ impl<B: BELStorage + Debug> Orchestrator<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
mod want_group {
|
||||||
|
use super::super::*;
|
||||||
|
use crate::{PartitionRef, WantDetail};
|
||||||
|
use crate::build_event_log::MemoryBELStorage;
|
||||||
|
|
||||||
|
fn create_job_config(label: &str, pattern: &str) -> JobConfiguration {
|
||||||
|
JobConfiguration {
|
||||||
|
label: label.to_string(),
|
||||||
|
pattern: pattern.to_string(),
|
||||||
|
entrypoint: "test_entrypoint".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_want_detail(want_id: &str, partition_refs: Vec<&str>) -> WantDetail {
|
||||||
|
WantDetail {
|
||||||
|
want_id: want_id.to_string(),
|
||||||
|
refs: partition_refs.iter().map(|r| PartitionRef {
|
||||||
|
r#ref: r.to_string(),
|
||||||
|
}).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_group_wants_empty_config_empty_wants() {
|
||||||
|
let config = OrchestratorConfig { jobs: vec![] };
|
||||||
|
let wants = vec![];
|
||||||
|
|
||||||
|
let result = Orchestrator::<MemoryBELStorage>::group_wants(&config, &wants);
|
||||||
|
|
||||||
|
assert!(result.want_groups.is_empty());
|
||||||
|
assert!(result.unhandled_wants.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_group_wants_one_want_matches_job() {
|
||||||
|
let job_config = create_job_config("test_job", "partition.*");
|
||||||
|
let config = OrchestratorConfig { jobs: vec![job_config.clone()] };
|
||||||
|
let want = create_want_detail("want1", vec!["partition1"]);
|
||||||
|
let wants = vec![want.clone()];
|
||||||
|
|
||||||
|
let result = Orchestrator::<MemoryBELStorage>::group_wants(&config, &wants);
|
||||||
|
|
||||||
|
assert!(result.unhandled_wants.is_empty());
|
||||||
|
assert_eq!(result.want_groups.len(), 1);
|
||||||
|
assert_eq!(result.want_groups[0].job.label, "test_job");
|
||||||
|
assert_eq!(result.want_groups[0].wants.len(), 1);
|
||||||
|
assert_eq!(result.want_groups[0].wants[0].want_id, "want1");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_group_wants_one_unmatching_want() {
|
||||||
|
let job_config = create_job_config("test_job", "^test_pattern$");
|
||||||
|
let config = OrchestratorConfig { jobs: vec![job_config] };
|
||||||
|
let want = create_want_detail("want1", vec!["different_partition"]);
|
||||||
|
let wants = vec![want.clone()];
|
||||||
|
|
||||||
|
let result = Orchestrator::<MemoryBELStorage>::group_wants(&config, &wants);
|
||||||
|
|
||||||
|
assert_eq!(result.unhandled_wants.len(), 1);
|
||||||
|
assert_eq!(result.unhandled_wants[0].want_id, "want1");
|
||||||
|
assert!(result.want_groups.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_group_wants_multiple_wants_different_jobs() {
|
||||||
|
let job_config1 = create_job_config("job1", "pattern1.*");
|
||||||
|
let job_config2 = create_job_config("job2", "pattern2.*");
|
||||||
|
let config = OrchestratorConfig { jobs: vec![job_config1, job_config2] };
|
||||||
|
|
||||||
|
let want1 = create_want_detail("want1", vec!["pattern1_partition"]);
|
||||||
|
let want2 = create_want_detail("want2", vec!["pattern1_other"]);
|
||||||
|
let want3 = create_want_detail("want3", vec!["pattern2_partition"]);
|
||||||
|
let wants = vec![want1, want2, want3];
|
||||||
|
|
||||||
|
let result = Orchestrator::<MemoryBELStorage>::group_wants(&config, &wants);
|
||||||
|
|
||||||
|
assert!(result.unhandled_wants.is_empty());
|
||||||
|
assert_eq!(result.want_groups.len(), 2);
|
||||||
|
|
||||||
|
// Find job1 group
|
||||||
|
let job1_group = result.want_groups.iter().find(|wg| wg.job.label == "job1").unwrap();
|
||||||
|
assert_eq!(job1_group.wants.len(), 2);
|
||||||
|
|
||||||
|
// Find job2 group
|
||||||
|
let job2_group = result.want_groups.iter().find(|wg| wg.job.label == "job2").unwrap();
|
||||||
|
assert_eq!(job2_group.wants.len(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue