Skip to content

Commit

Permalink
fixup! more get-test-job logging
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Oct 14, 2024
1 parent bfadd36 commit c0037b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ci/test-git-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ while true; do

[[ ${#TEST_JOB[@]} != 0 && ${TEST_JOB[0]} == TEST_JOB ]] && break

echo "No test job available"
echo "test-git-branch: No test job available"
$ktest_once && exit 1

sleep 10
Expand Down
37 changes: 24 additions & 13 deletions src/bin/get-test-job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn get_test_job(args: &Args, rc: &Ktestrc, durations: Option<&[u8]>) -> Option<T
.open(rc.output_dir.join("jobs")).unwrap();
let mut len = file.metadata().unwrap().len();
if len == 0 {
eprintln!("get-test-job: No test job available");
return None;
}

Expand All @@ -60,32 +61,34 @@ fn get_test_job(args: &Args, rc: &Ktestrc, durations: Option<&[u8]>) -> Option<T
let mut ret = None;

for job in map.rsplit(|b| *b == b'\n') {
let job = str::from_utf8(job).unwrap();

if job.is_empty() {
continue;
}

if args.verbose {
eprintln!("considering {}", std::str::from_utf8(job).unwrap());
eprintln!("get-test-job: considering {}", job);
}

let mut fields = job.split(|b| *b == b' ');
let branch = str::from_utf8(fields.next().unwrap()).unwrap();
let commit = str::from_utf8(fields.next().unwrap()).unwrap();
let age_str = str::from_utf8(fields.next().unwrap()).unwrap();
let mut fields = job.split(' ');
let branch = fields.next().unwrap();
let commit = fields.next().unwrap();
let age_str = fields.next().unwrap();
let age = str::parse::<u64>(age_str).unwrap();
let test = str::from_utf8(fields.next().unwrap()).unwrap();
let subtest = str::from_utf8(fields.next().unwrap()).unwrap();
let test = fields.next().unwrap();
let subtest = fields.next().unwrap();

if ret.is_some() && !commit_test_matches(&ret, commit, test) {
if args.verbose {
eprintln!("subtest from different test as previous, breaking");
eprintln!("get-test-job: subtest from different test as previous, breaking");
}
break;
}

let stats = test_stats(durations, test, subtest);
if args.verbose {
eprintln!("stats for {}.{}={:?}", test, subtest, stats);
eprintln!("get-test-job: stats for {}.{}={:?}", test, subtest, stats);
}
let duration_secs = if let Some(s) = stats {
s.duration
Expand All @@ -95,7 +98,7 @@ fn get_test_job(args: &Args, rc: &Ktestrc, durations: Option<&[u8]>) -> Option<T

if duration_sum != 0 && duration_sum + duration_secs > rc.subtest_duration_max {
if args.verbose {
eprintln!("have {} > {} seconds of work, breaking",
eprintln!("get-test-job: have {} > {} seconds of work, breaking",
duration_sum + duration_secs, rc.subtest_duration_max);
}
break;
Expand All @@ -104,7 +107,7 @@ fn get_test_job(args: &Args, rc: &Ktestrc, durations: Option<&[u8]>) -> Option<T
if !lockfile_exists(rc, &commit, &subtest_full_name(&test, &subtest),
!args.dry_run, &mut commits_updated) {
if args.verbose {
eprintln!("test already in progress");
eprintln!("get-test-job: test {} already in progress", job);
}
continue;
}
Expand All @@ -126,13 +129,20 @@ fn get_test_job(args: &Args, rc: &Ktestrc, durations: Option<&[u8]>) -> Option<T
}

if !args.dry_run {
let _ = file.set_len(len);
let r = file.set_len(len);
if let Err(e) = r {
eprintln!("get-test-job: error truncating jobs file: {}", e);
}
}

for i in commits_updated.iter() {
commit_update_results_from_fs(rc, &i);
}

if args.verbose {
eprintln!("get-test-job: got {:?}", ret);
}

ret
}

Expand All @@ -145,7 +155,8 @@ fn main() {
process::exit(1);
}
let rc = rc.unwrap();
let rc = rc.ktest;
let mut rc = rc.ktest;
rc.verbose = std::cmp::max(rc.verbose, args.verbose);

let durations_file = File::open(rc.output_dir.join("test_durations.capnp")).ok();
let durations_map = durations_file.map(|x| unsafe { MmapOptions::new().map(&x).ok() } ).flatten();
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct Ktestrc {
pub users_dir: PathBuf,
pub subtest_duration_max: u64,
pub subtest_duration_def: u64,
#[serde(default)]
pub verbose: bool,
}

pub fn ktestrc_read() -> anyhow::Result<Ktestrc> {
Expand Down Expand Up @@ -249,8 +251,12 @@ pub fn workers_get(ktestrc: &Ktestrc) -> anyhow::Result<Workers> {

use file_lock::{FileLock, FileOptions};

pub fn workers_update(ktestrc: &Ktestrc, n: Worker) -> Option<()> {
let fname = ktestrc.output_dir.join("workers.capnp");
pub fn workers_update(rc: &Ktestrc, n: Worker) -> Option<()> {
if rc.verbose {
eprintln!("workers_update: {:?}", n);
}

let fname = rc.output_dir.join("workers.capnp");
let foptions = FileOptions::new().read(true).write(true).append(false).create(true);

let mut filelock = FileLock::lock(fname, true, foptions)
Expand Down

0 comments on commit c0037b0

Please sign in to comment.