diff --git a/apps/albedo/test/albedo/composition/stream_http_test.gleam b/apps/albedo/test/albedo/composition/stream_http_test.gleam index 35be9ba75..02df4b209 100644 --- a/apps/albedo/test/albedo/composition/stream_http_test.gleam +++ b/apps/albedo/test/albedo/composition/stream_http_test.gleam @@ -9,6 +9,7 @@ import albedo_model/refusal import albedo_model_stream/http import albedo_openai import albedo_openai/stream as reducer +import albedo_protect import gleam/option.{None, Some} import gleam/string_tree import gleeunit/should @@ -76,7 +77,11 @@ pub fn invalid_headers_are_nonretryable_for_streams_and_bodies_test() -> Nil { /// Keepalive comments carry no event, so they hold off the idle budget but /// not the first-event deadline. pub fn the_first_event_deadline_outlasts_keepalives_test() -> Nil { + // Cold transport loading can consume the entire first-event budget under + // CPU contention. Read real headers before measuring keepalive handling. + prepare_transport() let fixture = start() + use <- albedo_protect.finally(after: fn() { stop(fixture) }) albedo_openai.exchange( albedo_openai.Exchange( url(fixture), @@ -93,5 +98,21 @@ pub fn the_first_event_deadline_outlasts_keepalives_test() -> Nil { fn(_) { types.Continue }, ) |> should.equal(Error(types.Timeout(types.AwaitingFirstEvent, 300))) - stop(fixture) +} + +fn prepare_transport() -> Nil { + let fixture = start() + use <- albedo_protect.finally(after: fn() { stop(fixture) }) + let assert Ok(connection) = + albedo_http.open( + albedo_http.options(), + url(fixture), + [], + string_tree.new(), + 2000, + ) + use <- albedo_http.with_connection(connection) + let assert Ok(albedo_http.Headers(200, _, False)) = + albedo_http.receive(connection) + Nil }