Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix embeddings cache test and image server port conflicts
- Use separate payload with "enabled": "on" for the second (cached)
  request in embeddings test (first request uses "write_only")
- Revert providers/common.rs image server to port 0 (uses fetch=true,
  so URL doesn't reach provider)
- Use port 0 for fetch_true image test, fixed port 19876 only for
  fetch_false (where URL IS in the provider request)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
AntoineToussaint and claude committed Apr 9, 2026
commit 0fbe2abf7b77cee48060887a47e313caf29b0dad
16 changes: 10 additions & 6 deletions crates/tensorzero-core/tests/e2e/image_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use uuid::Uuid;
use crate::providers::common::FERRIS_PNG;

/// Spawn a temporary HTTP server that serves the test image
async fn make_temp_image_server() -> (SocketAddr, tokio::sync::oneshot::Sender<()>) {
// Use a fixed port so that image URLs in provider requests are deterministic
// across test runs, enabling provider-proxy cache hits.
let addr = SocketAddr::from(([127, 0, 0, 1], 19876));
async fn make_temp_image_server_on_port(
port: u16,
) -> (SocketAddr, tokio::sync::oneshot::Sender<()>) {
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let listener = tokio::net::TcpListener::bind(addr)
.await
.unwrap_or_else(|e| panic!("Failed to bind to {addr}: {e}"));
Expand Down Expand Up @@ -149,7 +149,9 @@ async fn test_image_url_with_fetch_true() {
let episode_id = Uuid::now_v7();

// The '_shutdown_sender' will wake up the receiver on drop
let (server_addr, _shutdown_sender) = make_temp_image_server().await;
// Port 0 is fine here: fetch=true means the gateway downloads the image
// and sends base64 to the provider, so the port doesn't affect cache keys.
let (server_addr, _shutdown_sender) = make_temp_image_server_on_port(0).await;
let image_url = Url::parse(&format!("http://{server_addr}/ferris.png")).unwrap();

let client =
Expand Down Expand Up @@ -244,7 +246,9 @@ async fn test_image_url_with_fetch_false() {
let episode_id = Uuid::now_v7();

// The '_shutdown_sender' will wake up the receiver on drop
let (server_addr, _shutdown_sender) = make_temp_image_server().await;
// Fixed port: fetch=false means the URL is passed directly to the provider,
// so it must be deterministic for provider-proxy cache hits.
let (server_addr, _shutdown_sender) = make_temp_image_server_on_port(19876).await;
let image_url = Url::parse(&format!("https://{server_addr}/ferris.png")).unwrap();

let client =
Expand Down
6 changes: 3 additions & 3 deletions crates/tensorzero-core/tests/e2e/providers/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,9 +1688,9 @@ pub async fn test_image_inference_with_provider_s3_compatible(
}

async fn make_temp_image_server() -> (SocketAddr, tokio::sync::oneshot::Sender<()>) {
// Use a fixed port so that image URLs in provider requests are deterministic
// across test runs, enabling provider-proxy cache hits.
let addr = SocketAddr::from(([127, 0, 0, 1], 19877));
// Port 0 is fine here: fetch=true means the gateway downloads the image
// and sends base64 to the provider, so the port doesn't affect cache keys.
let addr = SocketAddr::from(([127, 0, 0, 1], 0));
let listener = tokio::net::TcpListener::bind(addr)
.await
.unwrap_or_else(|e| panic!("Failed to bind to {addr}: {e}"));
Expand Down
13 changes: 11 additions & 2 deletions crates/tensorzero-core/tests/e2e/raw_response/embeddings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,19 @@ async fn test_embeddings_raw_response_with_cache() {
// Wait for cache write to complete
tokio::time::sleep(std::time::Duration::from_secs(2)).await;

// Second request: should hit cache
// Second request: cache enabled (should hit cache written by the first request)
let cached_payload = json!({
"input": input_text,
"model": "tensorzero::embedding_model_name::text-embedding-3-small",
"tensorzero::include_raw_response": true,
"tensorzero::cache_options": {
"enabled": "on",
"max_age_s": 60
}
});
let response_cached = Client::new()
.post(get_gateway_endpoint("/openai/v1/embeddings"))
.json(&payload)
.json(&cached_payload)
.send()
.await
.unwrap();
Expand Down
Loading