这是indexloc提供的服务,不要输入任何密码
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
45 changes: 40 additions & 5 deletions crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,14 @@ mod test {
#[tokio::test]
async fn test_do_preflight() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let base_url = format!("http://localhost:{port}");

let client = APIClient::new(
Expand Down Expand Up @@ -885,7 +892,14 @@ mod test {
#[tokio::test]
async fn test_content_length() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let base_url = format!("http://localhost:{port}");

let client = APIClient::new(
Expand Down Expand Up @@ -920,7 +934,14 @@ mod test {
#[tokio::test]
async fn test_record_telemetry_success() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let base_url = format!("http://localhost:{port}");

let client = AnonAPIClient::new(&base_url, 10, "2.0.0")?;
Expand Down Expand Up @@ -955,7 +976,14 @@ mod test {
#[tokio::test]
async fn test_record_telemetry_empty_events() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let base_url = format!("http://localhost:{port}");

let client = AnonAPIClient::new(&base_url, 10, "2.0.0")?;
Expand All @@ -977,7 +1005,14 @@ mod test {
#[tokio::test]
async fn test_record_telemetry_with_different_event_types() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let base_url = format!("http://localhost:{port}");

let client = AnonAPIClient::new(&base_url, 10, "2.0.0")?;
Expand Down
12 changes: 10 additions & 2 deletions crates/turborepo-auth/src/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub async fn login<T: Client + TokenClient + CacheClient>(

#[cfg(test)]
mod tests {
use std::{assert_matches::assert_matches, sync::atomic::AtomicUsize};
use std::{assert_matches::assert_matches, sync::atomic::AtomicUsize, time::Duration};

use async_trait::async_trait;
use reqwest::{Method, RequestBuilder, Response};
Expand Down Expand Up @@ -359,7 +359,15 @@ mod tests {
#[tokio::test]
async fn test_login() {
let port = port_scanner::request_open_port().unwrap();
let api_server = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let api_server = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.expect("Test server failed to start")
.expect("Server setup failed");

let color_config = ColorConfig::new(false);
let url = format!("http://localhost:{port}");

Expand Down
12 changes: 10 additions & 2 deletions crates/turborepo-auth/src/auth/sso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub async fn sso_login<T: Client + TokenClient + CacheClient>(

#[cfg(test)]
mod tests {
use std::{assert_matches::assert_matches, sync::atomic::AtomicUsize};
use std::{assert_matches::assert_matches, sync::atomic::AtomicUsize, time::Duration};

use async_trait::async_trait;
use reqwest::{Method, RequestBuilder, Response};
Expand Down Expand Up @@ -375,7 +375,15 @@ mod tests {
#[tokio::test]
async fn test_sso_login() {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.expect("Test server failed to start")
.expect("Server setup failed");

let url = format!("http://localhost:{port}");
let color_config = ColorConfig::new(false);
let team = "something";
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-cache/src/async_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ mod tests {
#[tokio::test]
async fn test_async_cache() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

try_join_all(get_test_cases().into_iter().map(|test_case| async move {
round_trip_test_with_both_caches(&test_case, port).await?;
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-cache/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ mod test {
#[tokio::test]
async fn test_fs_cache() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let test_cases = get_test_cases();

Expand Down
9 changes: 8 additions & 1 deletion crates/turborepo-cache/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,14 @@ mod test {
#[tokio::test]
async fn test_http_cache() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for the server to be ready (with timeout)
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start within timeout"))??;

let test_cases = get_test_cases();

try_join_all(
Expand Down
11 changes: 9 additions & 2 deletions crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ fn add_turbo_to_gitignore(base: &CommandBase) -> Result<(), io::Error> {

#[cfg(test)]
mod test {
use std::fs;
use std::{fs, time::Duration};

use anyhow::Result;
use tempfile::{NamedTempFile, TempDir};
Expand Down Expand Up @@ -427,7 +427,14 @@ mod test {
.unwrap();

let port = port_scanner::request_open_port().unwrap();
let handle = tokio::spawn(start_test_server(port));
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let handle = tokio::spawn(start_test_server(port, Some(ready_tx)));

// Wait for server to be ready
tokio::time::timeout(Duration::from_secs(5), ready_rx)
.await
.map_err(|_| anyhow::anyhow!("Test server failed to start"))??;

let override_global_config_path =
AbsoluteSystemPathBuf::try_from(user_config_file.path().to_path_buf())?;

Expand Down
11 changes: 10 additions & 1 deletion crates/turborepo-vercel-api-mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ pub const EXPECTED_TEAM_CREATED_AT: u64 = 0;
pub const EXPECTED_SSO_TEAM_ID: &str = "expected_sso_team_id";
pub const EXPECTED_SSO_TEAM_SLUG: &str = "expected_sso_team_slug";

pub async fn start_test_server(port: u16) -> Result<()> {
pub async fn start_test_server(
port: u16,
ready_tx: Option<tokio::sync::oneshot::Sender<()>>,
) -> Result<()> {
let get_durations_ref = Arc::new(Mutex::new(HashMap::new()));
let head_durations_ref = get_durations_ref.clone();
let put_durations_ref = get_durations_ref.clone();
Expand Down Expand Up @@ -240,6 +243,12 @@ pub async fn start_test_server(port: u16) -> Result<()> {

let addr = SocketAddr::from(([127, 0, 0, 1], port));
let listener = TcpListener::bind(addr).await?;

// Signal that the server is ready to accept connections
if let Some(tx) = ready_tx {
let _ = tx.send(());
}

// We print the port so integration tests can use it
println!("{port}");
axum::serve(listener, app).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-vercel-api-mock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use turborepo_vercel_api_mock::start_test_server;
#[tokio::main]
async fn main() -> Result<()> {
let port = port_scanner::request_open_port().unwrap();
tokio::task::block_in_place(|| start_test_server(port)).await?;
tokio::task::block_in_place(|| start_test_server(port, None)).await?;
Ok(())
}
Loading