From 506966ae1b1125424ac54654d579b00e87bee667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Kleinem=C3=BChl?= Date: Thu, 6 Jun 2024 13:50:35 +0200 Subject: [PATCH] Slurm collector: Add tests for cancelled jobs --- collectors/slurm/src/sacctcaller.rs | 220 +++++++++++++++++++++++++++- 1 file changed, 219 insertions(+), 1 deletion(-) diff --git a/collectors/slurm/src/sacctcaller.rs b/collectors/slurm/src/sacctcaller.rs index 5156a292d..b37009def 100644 --- a/collectors/slurm/src/sacctcaller.rs +++ b/collectors/slurm/src/sacctcaller.rs @@ -246,7 +246,10 @@ fn parse_sacct_rows(sacct_rows: SacctRows, keys: &[KeyConfig]) -> Result::from( + NaiveDateTime::parse_from_str( + "2023-11-07T10:14:01", + "%Y-%m-%dT%H:%M:%S", + ) + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()) + .unwrap(), + ) + .unwrap(), + ))), + ), + ( + END.to_owned(), + Some(AllowedTypes::DateTime(DateTime::::from( + NaiveDateTime::parse_from_str( + "2023-11-07T11:39:09", + "%Y-%m-%dT%H:%M:%S", + ) + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()) + .unwrap(), + ) + .unwrap(), + ))), + ), + ( + STATE.to_owned(), + Some(AllowedTypes::String("CANCELLED by 1000".to_owned())), + ), + ]), + ), + ( + "1234567.batch".to_owned(), + SacctRow::from([ + ( + JOBID.to_owned(), + Some(AllowedTypes::String("1234567.batch".to_owned())), + ), + ( + START.to_owned(), + Some(AllowedTypes::DateTime(DateTime::::from( + NaiveDateTime::parse_from_str( + "2023-11-07T10:14:01", + "%Y-%m-%dT%H:%M:%S", + ) + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()) + .unwrap(), + ) + .unwrap(), + ))), + ), + ( + END.to_owned(), + Some(AllowedTypes::DateTime(DateTime::::from( + NaiveDateTime::parse_from_str( + "2023-11-07T11:39:09", + "%Y-%m-%dT%H:%M:%S", + ) + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()) + .unwrap(), + ) + .unwrap(), + ))), + ), + ( + STATE.to_owned(), + Some(AllowedTypes::String("CANCELLED by 1000".to_owned())), + ), + ]), + ), + ]); + + let parsed_sacct_rows = parse_sacct_rows(sacct_rows, &keys).unwrap(); + + let expected = vec![Job::from([ + ( + "JobID".to_owned(), + AllowedTypes::String("1234567".to_owned()), + ), + ( + START.to_owned(), + AllowedTypes::DateTime(DateTime::::from( + NaiveDateTime::parse_from_str("2023-11-07T10:14:01", "%Y-%m-%dT%H:%M:%S") + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()).unwrap(), + ) + .unwrap(), + )), + ), + ( + END.to_owned(), + AllowedTypes::DateTime(DateTime::::from( + NaiveDateTime::parse_from_str("2023-11-07T11:39:09", "%Y-%m-%dT%H:%M:%S") + .unwrap() + .and_local_timezone( + FixedOffset::east_opt(Local::now().offset().local_minus_utc()).unwrap(), + ) + .unwrap(), + )), + ), + ( + STATE.to_owned(), + AllowedTypes::String("CANCELLED by 1000".to_owned()), + ), + ])]; + assert_eq!(parsed_sacct_rows, expected); + } + #[test] fn construct_components_empty_config_succeeds() { let job = Job::from([(