fix rust ci failures

This commit is contained in:
elky
2026-06-01 02:42:10 +08:00
parent 0f4141ef3f
commit 6c2a57f237
3 changed files with 173 additions and 142 deletions
+29 -4
View File
@@ -19,6 +19,27 @@ fn large_request_body(stream: bool) -> String {
.expect("request body should encode") .expect("request body should encode")
} }
fn run_async_test_on_large_stack<F>(name: &'static str, future: F)
where
F: std::future::Future<Output = ()> + Send + 'static,
{
let handle = std::thread::Builder::new()
.name(name.to_string())
.stack_size(16 * 1024 * 1024)
.spawn(move || {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio runtime should build")
.block_on(future);
})
.expect("large-stack usage direct test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[tokio::test] #[tokio::test]
async fn gateway_records_usage_for_execution_runtime_sync_when_runtime_enabled() { async fn gateway_records_usage_for_execution_runtime_sync_when_runtime_enabled() {
let usage_repository = Arc::new(InMemoryUsageReadRepository::default()); let usage_repository = Arc::new(InMemoryUsageReadRepository::default());
@@ -131,8 +152,9 @@ async fn gateway_records_usage_for_execution_runtime_sync_when_runtime_enabled()
upstream_handle.abort(); upstream_handle.abort();
} }
#[tokio::test] #[test]
async fn gateway_records_pending_usage_before_execution_runtime_sync_result_arrives() { fn gateway_records_pending_usage_before_execution_runtime_sync_result_arrives() {
run_async_test_on_large_stack("pending-usage-sync-before-runtime-result", async move {
let usage_repository = Arc::new(InMemoryUsageReadRepository::default()); let usage_repository = Arc::new(InMemoryUsageReadRepository::default());
let request_candidate_repository = Arc::new(InMemoryRequestCandidateRepository::default()); let request_candidate_repository = Arc::new(InMemoryRequestCandidateRepository::default());
let execution_request_started = Arc::new(tokio::sync::Notify::new()); let execution_request_started = Arc::new(tokio::sync::Notify::new());
@@ -197,7 +219,8 @@ async fn gateway_records_pending_usage_before_execution_runtime_sync_result_arri
)); ));
let (upstream_url, upstream_handle) = start_server(upstream).await; let (upstream_url, upstream_handle) = start_server(upstream).await;
let (execution_runtime_url, execution_runtime_handle) = start_server(execution_runtime).await; let (execution_runtime_url, execution_runtime_handle) =
start_server(execution_runtime).await;
let gateway_state = let gateway_state =
build_state_with_execution_runtime_override(execution_runtime_url) build_state_with_execution_runtime_override(execution_runtime_url)
.with_data_state_for_tests( .with_data_state_for_tests(
@@ -254,7 +277,8 @@ async fn gateway_records_pending_usage_before_execution_runtime_sync_result_arri
} }
tokio::time::sleep(std::time::Duration::from_millis(10)).await; tokio::time::sleep(std::time::Duration::from_millis(10)).await;
} }
let pending = pending.expect("pending usage should be recorded before sync result resolves"); let pending =
pending.expect("pending usage should be recorded before sync result resolves");
assert_eq!(pending.status, "pending"); assert_eq!(pending.status, "pending");
assert_eq!(pending.billing_status, "pending"); assert_eq!(pending.billing_status, "pending");
assert_eq!(pending.response_time_ms, None); assert_eq!(pending.response_time_ms, None);
@@ -282,6 +306,7 @@ async fn gateway_records_pending_usage_before_execution_runtime_sync_result_arri
gateway_handle.abort(); gateway_handle.abort();
execution_runtime_handle.abort(); execution_runtime_handle.abort();
upstream_handle.abort(); upstream_handle.abort();
});
} }
#[tokio::test] #[tokio::test]
@@ -44,8 +44,7 @@ static DRAIN_DEADLINE_MS: LazyLock<u64> = LazyLock::new(|| {
static STREAM_MIN_WINDOW_UPDATE_BYTES: LazyLock<u32> = LazyLock::new(|| { static STREAM_MIN_WINDOW_UPDATE_BYTES: LazyLock<u32> = LazyLock::new(|| {
STREAM_INITIAL_WINDOW_BYTES STREAM_INITIAL_WINDOW_BYTES
.saturating_div(4) .saturating_div(4)
.max(1) .clamp(1, 1024 * 1024)
.min(1024 * 1024)
}); });
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -376,9 +375,8 @@ impl ProxyConn {
} }
pub fn update_protocol_version(&self, protocol_version: u8) { pub fn update_protocol_version(&self, protocol_version: u8) {
let negotiated = protocol_version let negotiated =
.max(1) protocol_version.clamp(1, aether_contracts::tunnel::CURRENT_TUNNEL_PROTOCOL_VERSION);
.min(aether_contracts::tunnel::CURRENT_TUNNEL_PROTOCOL_VERSION);
self.protocol_version.store(negotiated, Ordering::Relaxed); self.protocol_version.store(negotiated, Ordering::Relaxed);
} }
+22 -14
View File
@@ -1394,17 +1394,14 @@ pub async fn handle_stream(
server.active_connections.fetch_add(1, Ordering::Release); server.active_connections.fetch_add(1, Ordering::Release);
let connect_elapsed = handle_stream_inner( let stream_io = StreamIo {
&state,
&server,
stream_id,
meta,
body_rx, body_rx,
&frame_tx, frame_tx: &frame_tx,
response_window.as_ref(), response_window: response_window.as_ref(),
permit, admission_permit: permit,
) };
.await;
let connect_elapsed = handle_stream_inner(&state, &server, stream_id, meta, stream_io).await;
server.active_connections.fetch_sub(1, Ordering::Release); server.active_connections.fetch_sub(1, Ordering::Release);
if let Some(d) = connect_elapsed { if let Some(d) = connect_elapsed {
@@ -1459,16 +1456,27 @@ async fn send_frame(tx: &FrameSender, frame: TunnelFrame) -> bool {
/// Returns the connection-establishment duration (DNS + TCP/TLS + TTFB) if the /// Returns the connection-establishment duration (DNS + TCP/TLS + TTFB) if the
/// upstream request succeeded, or `None` if the request never reached the /// upstream request succeeded, or `None` if the request never reached the
/// response-headers stage. /// response-headers stage.
struct StreamIo<'a> {
body_rx: mpsc::Receiver<TunnelFrame>,
frame_tx: &'a FrameSender,
response_window: &'a StreamSendWindow,
admission_permit: Option<AdmissionPermit>,
}
async fn handle_stream_inner( async fn handle_stream_inner(
state: &AppState, state: &AppState,
server: &ServerContext, server: &ServerContext,
stream_id: u32, stream_id: u32,
meta: RequestMeta, meta: RequestMeta,
body_rx: mpsc::Receiver<TunnelFrame>, stream_io: StreamIo<'_>,
frame_tx: &FrameSender,
response_window: &StreamSendWindow,
mut admission_permit: Option<AdmissionPermit>,
) -> Option<Duration> { ) -> Option<Duration> {
let StreamIo {
body_rx,
frame_tx,
response_window,
mut admission_permit,
} = stream_io;
let mut current_method: hyper::Method = parse_request_method(&meta.method); let mut current_method: hyper::Method = parse_request_method(&meta.method);
let mut current_url = match url::Url::parse(&meta.url) { let mut current_url = match url::Url::parse(&meta.url) {
Ok(u) => u, Ok(u) => u,