mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Make the Guardian deadline cancellation helper crate-private (#45493)
## What changed Restrict `run_before_review_deadline_with_cancel` and its re-export to `codex-guardian-reviewer`. Move its timeout, abort, and successful-completion tests from core into the reviewer's deadline module, and remove the standalone `run_before_review_deadline` tests from core. GitOrigin-RevId: dd9f1ed571a40a4bd66b08c88f3ee2be071f4870
This commit is contained in:
1 parent
43da136850
commit
d3812ddbb3
5 files changed
+75
-105
No files matched your search
@@ -22,7 +22,7 @@ pub async fn run_before_review_deadline<T>(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_before_review_deadline_with_cancel<T>(
|
||||
pub(crate) async fn run_before_review_deadline_with_cancel<T>(
|
||||
deadline: tokio::time::Instant,
|
||||
external_cancel: Option<&CancellationToken>,
|
||||
cancel_token: &CancellationToken,
|
||||
@@ -34,3 +34,7 @@ pub async fn run_before_review_deadline_with_cancel<T>(
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "deadline_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,69 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use super::run_before_review_deadline_with_cancel;
|
||||
use crate::GuardianReviewSessionOutcome;
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn run_before_review_deadline_with_cancel_cancels_token_on_timeout() {
|
||||
let cancel_token = CancellationToken::new();
|
||||
|
||||
let outcome = run_before_review_deadline_with_cancel(
|
||||
tokio::time::Instant::now() + Duration::from_millis(10),
|
||||
/*external_cancel*/ None,
|
||||
&cancel_token,
|
||||
async {
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
Err(GuardianReviewSessionOutcome::TimedOut)
|
||||
));
|
||||
assert!(cancel_token.is_cancelled());
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn run_before_review_deadline_with_cancel_cancels_token_on_abort() {
|
||||
let external_cancel = CancellationToken::new();
|
||||
let external_canceller = external_cancel.clone();
|
||||
let cancel_token = CancellationToken::new();
|
||||
drop(tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
external_canceller.cancel();
|
||||
}));
|
||||
|
||||
let outcome = run_before_review_deadline_with_cancel(
|
||||
tokio::time::Instant::now() + Duration::from_secs(1),
|
||||
Some(&external_cancel),
|
||||
&cancel_token,
|
||||
std::future::pending::<()>(),
|
||||
)
|
||||
.await;
|
||||
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
Err(GuardianReviewSessionOutcome::Aborted)
|
||||
));
|
||||
assert!(cancel_token.is_cancelled());
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn run_before_review_deadline_with_cancel_preserves_token_on_success() {
|
||||
let cancel_token = CancellationToken::new();
|
||||
|
||||
let outcome = run_before_review_deadline_with_cancel(
|
||||
tokio::time::Instant::now() + Duration::from_secs(1),
|
||||
/*external_cancel*/ None,
|
||||
&cancel_token,
|
||||
async { 42usize },
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(outcome.unwrap(), 42);
|
||||
assert!(!cancel_token.is_cancelled());
|
||||
}
|
||||
@@ -40,7 +40,7 @@ pub const MAX_REVIEW_ATTEMPTS: i64 = 3;
|
||||
pub const REVIEW_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(90);
|
||||
|
||||
pub use deadline::run_before_review_deadline;
|
||||
pub use deadline::run_before_review_deadline_with_cancel;
|
||||
pub(crate) use deadline::run_before_review_deadline_with_cancel;
|
||||
pub use pool::ReviewerPool;
|
||||
pub use pool::ReviewerRequest;
|
||||
pub use pool::ReviewerSession;
|
||||
|
||||
Reference in new issue
Block a user