Skip to content

Commit

Permalink
fix(job): correct is_pending. add regression test for cleared job s…
Browse files Browse the repository at this point in the history
…tatus (#3099)
  • Loading branch information
wsxiaoys authored Sep 7, 2024
1 parent c4a947c commit 7919603
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 1 addition & 5 deletions ee/tabby-db/src/job_runs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ impl JobRunDAO {
}

pub fn is_pending(&self) -> bool {
self.started_at.is_none()
}

pub fn is_finished(&self) -> bool {
self.finished_at.is_some()
self.started_at.is_none() && self.exit_code.is_none()
}
}

Expand Down
8 changes: 8 additions & 0 deletions ee/tabby-webserver/src/service/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl JobService for JobControllerImpl {

#[cfg(test)]
mod tests {
use assert_matches::assert_matches;
use tabby_db::DbConn;

use super::*;
Expand Down Expand Up @@ -123,5 +124,12 @@ mod tests {
// As job1 is marked as stale, no jobs will be cleared.
assert_eq!(0, svc.clear(job1.to_command()).await.unwrap());
assert_eq!(1, svc.clear(job2.to_command()).await.unwrap());

// Regression test case, cleared job shouldn't be pending.
// job2 started_at is NULL, but exit code is -1
let job2dao = db.get_latest_job_run(job2.to_command()).await.unwrap();
assert!(job2dao.started_at.is_none());
assert_matches!(job2dao.exit_code, Some(-1));
assert!(!job2dao.is_pending())
}
}

0 comments on commit 7919603

Please sign in to comment.