Add direct upstream compatibility regression test

Co-authored-by: Maxim Myalin <maxim@myalin.ru>
This commit is contained in:
Cursor Agent 2026-03-22 12:41:22 +00:00
parent 140bf0e180
commit 38b11b085d
No known key found for this signature in database
1 changed files with 37 additions and 0 deletions

View File

@ -1807,6 +1807,7 @@ impl UpstreamManager {
mod tests {
use super::*;
use std::sync::Arc;
use tokio::net::TcpListener;
use crate::stats::Stats;
@ -1961,4 +1962,40 @@ mod tests {
);
assert_eq!(snapshot.upstreams[0].address, "127.0.0.1:8388");
}
#[tokio::test]
async fn connect_with_details_keeps_direct_tcp_compatibility() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let target = listener.local_addr().unwrap();
let accept_task = tokio::spawn(async move {
let (_stream, _peer) = listener.accept().await.unwrap();
});
let manager = UpstreamManager::new(
vec![UpstreamConfig {
upstream_type: UpstreamType::Direct {
interface: None,
bind_addresses: None,
},
weight: 1,
enabled: true,
scopes: String::new(),
selected_scope: String::new(),
}],
1,
100,
1000,
1,
false,
Arc::new(Stats::new()),
);
let (stream, egress) = manager
.connect_with_details(target, None, None)
.await
.expect("direct upstream should return a raw TCP stream");
assert_eq!(stream.peer_addr().unwrap(), target);
assert_eq!(egress.route_kind, UpstreamRouteKind::Direct);
accept_task.await.unwrap();
}
}