test(916): use far-future reset_at in inactivity-extension regression test to avoid spawn-time race
The original 90b31fc8 test computed reset_at = now + 3s in the test thread,
then relied on the script spawning fast enough that the rate_limit_event
arrived while reset_at was still meaningfully in the future. Under
cargo-test load the spawn could take long enough that block_until - now
clamped to 0 and the inactivity timeout killed the script before its sleep
finished. Pin reset_at to 2099-01-01 (matching the existing
rate_limit_hard_block_sends_watcher_hard_block_event test) so the
extension is essentially infinite and the assertion isolates the
extension-vs-no-extension behavior from wall-clock slack.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -208,21 +208,19 @@ mod tests {
|
||||
/// by the backoff duration so the watchdog doesn't kill the agent while
|
||||
/// it's legitimately waiting for the limit to clear.
|
||||
///
|
||||
/// Script emits a hard-block event with reset_at = now + 3s, then sleeps
|
||||
/// 3s, then exits. With inactivity_timeout_secs = 1, the run would fail
|
||||
/// without the extension; with it, the deadline is bumped to ~4s and the
|
||||
/// script gets to complete cleanly.
|
||||
/// Script emits a hard-block event with reset_at in the far future, then
|
||||
/// sleeps 3s, then exits. With inactivity_timeout_secs = 1, the run
|
||||
/// would normally fail at the 1s mark; with the extension the deadline
|
||||
/// is bumped past the sleep and the script completes cleanly. The
|
||||
/// far-future reset_at avoids wall-clock races under cargo-test load.
|
||||
#[tokio::test]
|
||||
async fn rate_limit_hard_block_extends_inactivity_deadline() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let script = tmp.path().join("emit_then_wait.sh");
|
||||
let reset_at = chrono::Utc::now() + chrono::Duration::seconds(3);
|
||||
let reset_at_str = reset_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
|
||||
let body = format!(
|
||||
"#!/bin/sh\nprintf '%s\\n' '{{\"type\":\"rate_limit_event\",\"rate_limit_info\":{{\"status\":\"hard_block\",\"reset_at\":\"{reset_at_str}\"}}}}'\nsleep 3\n"
|
||||
);
|
||||
let body =
|
||||
"#!/bin/sh\nprintf '%s\\n' '{\"type\":\"rate_limit_event\",\"rate_limit_info\":{\"status\":\"hard_block\",\"reset_at\":\"2099-01-01T12:00:00Z\"}}'\nsleep 3\n";
|
||||
std::fs::write(&script, body).unwrap();
|
||||
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user