INNER CODE UNIT · Rust
ncpus_and_job_index
ngless-toolkit/ngless · src/batch.rs:68
fn ncpus_and_job_index() {
// Save and restore so the test leaves the environment as it found it.
let saved: Vec<(&str, Option<String>)> =
VARS.iter().map(|v| (*v, env::var(v).ok())).collect();
clear();
assert_eq!(get_job_index(), None);
assert_eq!(get_ncpus(), None);
// LSF index, then SGE index, then LSF-wins-over-SGE precedence.
env::set_var("SGE_TASK_ID", "3");
assert_eq!(get_job_index(), Some(3));
env::set_var("LSB_JOBINDEX", "9");
assert_eq!(get_job_index(), Some(9));
// Unparseable values are ignored (mirrors `readMaybe`).
env::set_var("LSB_JOBINDEX", "abc");
assert_eq!(get_job_index(), Some(3)); // falls back to SGE_TASK_ID