mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-05 00:47:48 +08:00
refactor(gateway): 重构格式转换候选资格检查并优化测试基础设施
- 将 format_conversion_disabled 的过滤提前到候选遴选阶段,替代原来的 skip_reason 标记机制 - 为测试添加 execution_runtime_sync_override 直接注入支持,避免启动额外 HTTP 服务器 - 将 submit_terminal_event 改为 async record_terminal_event 确保失败用量事件可靠入库 - 新增 test_support 模块封装可重试的 loopback 端口绑定逻辑 - 前端:poolTrace 将 skipped 从隐藏状态移除,新增 buildPoolParticipatedCandidates 统一新旧链路逻辑,并将 skipped 状态色改为 foreground
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
const LOOPBACK_BIND_MAX_ATTEMPTS: usize = 120;
|
||||
const LOOPBACK_BIND_RETRY_DELAY: Duration = Duration::from_millis(50);
|
||||
|
||||
pub(crate) async fn bind_loopback_listener() -> io::Result<tokio::net::TcpListener> {
|
||||
let mut last_retryable_error = None;
|
||||
|
||||
for attempt in 1..=LOOPBACK_BIND_MAX_ATTEMPTS {
|
||||
match tokio::net::TcpListener::bind("127.0.0.1:0").await {
|
||||
Ok(listener) => return Ok(listener),
|
||||
Err(err)
|
||||
if attempt < LOOPBACK_BIND_MAX_ATTEMPTS
|
||||
&& is_retryable_loopback_bind_error(&err) =>
|
||||
{
|
||||
last_retryable_error = Some(err);
|
||||
tokio::time::sleep(LOOPBACK_BIND_RETRY_DELAY).await;
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
let err =
|
||||
last_retryable_error.expect("loopback bind retries should record the last retryable error");
|
||||
Err(io::Error::new(
|
||||
err.kind(),
|
||||
format!("loopback bind failed after {LOOPBACK_BIND_MAX_ATTEMPTS} attempts: {err}"),
|
||||
))
|
||||
}
|
||||
|
||||
fn is_retryable_loopback_bind_error(err: &io::Error) -> bool {
|
||||
matches!(
|
||||
err.kind(),
|
||||
io::ErrorKind::PermissionDenied
|
||||
| io::ErrorKind::AddrInUse
|
||||
| io::ErrorKind::AddrNotAvailable
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user