mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
otel test: retry WouldBlock errors (#8915)
This test looks flaky on Windows:
```
FAIL [ 0.034s] (1442/2802) codex-otel::tests suite::otlp_http_loopback::otlp_http_exporter_sends_metrics_to_collector
stdout ───
running 1 test
test suite::otlp_http_loopback::otlp_http_exporter_sends_metrics_to_collector ... FAILED
failures:
failures:
suite::otlp_http_loopback::otlp_http_exporter_sends_metrics_to_collector
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 14 filtered out; finished in 0.02s
stderr ───
Error: ProviderShutdown { source: InternalFailure("[InternalFailure(\"Failed to shutdown\")]") }
────────────
Summary [ 175.360s] 2802 tests run: 2801 passed, 1 failed, 15 skipped
FAIL [ 0.034s] (1442/2802) codex-otel::tests suite::otlp_http_loopback::otlp_http_exporter_sends_metrics_to_collector
```
This commit is contained in:
@@ -23,11 +23,33 @@ fn read_http_request(
|
||||
stream: &mut TcpStream,
|
||||
) -> std::io::Result<(String, HashMap<String, String>, Vec<u8>)> {
|
||||
stream.set_read_timeout(Some(Duration::from_secs(2)))?;
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
|
||||
let mut read_next = |buf: &mut [u8]| -> std::io::Result<usize> {
|
||||
loop {
|
||||
match stream.read(buf) {
|
||||
Ok(n) => return Ok(n),
|
||||
Err(err)
|
||||
if err.kind() == std::io::ErrorKind::WouldBlock
|
||||
|| err.kind() == std::io::ErrorKind::Interrupted =>
|
||||
{
|
||||
if Instant::now() >= deadline {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::TimedOut,
|
||||
"timed out waiting for request data",
|
||||
));
|
||||
}
|
||||
thread::sleep(Duration::from_millis(5));
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut buf = Vec::new();
|
||||
let mut scratch = [0u8; 8192];
|
||||
let header_end = loop {
|
||||
let n = stream.read(&mut scratch)?;
|
||||
let n = read_next(&mut scratch)?;
|
||||
if n == 0 {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
@@ -79,7 +101,7 @@ fn read_http_request(
|
||||
.and_then(|v| v.parse::<usize>().ok())
|
||||
{
|
||||
while body_bytes.len() < len {
|
||||
let n = stream.read(&mut scratch)?;
|
||||
let n = read_next(&mut scratch)?;
|
||||
if n == 0 {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
|
||||
Reference in New Issue
Block a user