Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion desktop/src-tauri/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,12 @@ mod tests {

#[tokio::test]
async fn oversized_hint_is_capped_in_relay_error_message_string() {
use crate::relay_admission::MAX_HINT_SECONDS;
use crate::relay_admission::{reset_rate_limit_gate, MAX_HINT_SECONDS, TEST_SERIAL};
use std::io::{Read as _, Write as _};

let _serial = TEST_SERIAL.lock().await;
reset_rate_limit_gate();

// Use a std::net listener on a std::thread — the same pattern as the
// relay_admission loopback tests. This avoids two races that cause CI
// failures with tokio::net + into_std():
Expand Down Expand Up @@ -702,6 +705,7 @@ mod tests {
!msg.contains(&oversized.to_string()),
"raw oversized hint must not appear in the message string"
);
reset_rate_limit_gate();
}

// ── effective_agent_relay_url: legacy pin ignored ─────────────────────────
Expand Down
7 changes: 5 additions & 2 deletions desktop/src-tauri/src/relay_admission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub const MAX_HINT_SECONDS: u64 = 300;

static GATE_EXPIRY: Mutex<Option<Instant>> = Mutex::new(None);

// The gate is process-wide, so every test that can arm it must serialize.
#[cfg(test)]
pub(crate) static TEST_SERIAL: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());

/// Arm (or extend) the admission gate from a relay 429.
///
/// `retry_in_seconds` is the parsed `retry in Ns` hint, if the relay provided
Expand Down Expand Up @@ -105,9 +109,8 @@ mod tests {
use super::*;

// The gate is a process-wide static shared by every test in this binary,
// so all gate tests serialize on one async lock to keep armed expiries
// so all tests that arm it serialize on one async lock to keep expiries
// from bleeding between parallel test threads.
pub(crate) static TEST_SERIAL: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());

#[tokio::test(start_paused = true)]
async fn wait_returns_immediately_when_gate_is_inactive() {
Expand Down
Loading