mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Wait for reader cancellation in the RPC delay test (#65113)
## Why The reader task can take more than ten scheduler yields to drop the reader after a write error, causing the test to fail even when cancellation works. ## What changed Have the test reader signal its drop with Tokio's `Notify` and give `write_error_cancels_reader` up to five seconds to receive that signal after asserting the broken-pipe error. GitOrigin-RevId: fdb1fc8d9aaccaa72f85b51e11184df483420f80
This commit is contained in:
@@ -2,8 +2,6 @@ use std::collections::VecDeque;
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
@@ -17,6 +15,7 @@ use tokio::io::ReadBuf;
|
||||
use tokio::io::duplex;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::Notify;
|
||||
use tokio::time::advance;
|
||||
use tokio::time::timeout;
|
||||
|
||||
@@ -72,7 +71,7 @@ async fn burst_chunks_share_one_deadline() -> anyhow::Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn write_error_cancels_reader() {
|
||||
let reader_dropped = Arc::new(AtomicBool::new(false));
|
||||
let reader_dropped = Arc::new(Notify::new());
|
||||
let reader = PendingAfterChunkReader::new(Arc::clone(&reader_dropped));
|
||||
|
||||
let error = forward_direction(reader, FailingWriter, Duration::ZERO)
|
||||
@@ -80,13 +79,9 @@ async fn write_error_cancels_reader() {
|
||||
.expect_err("failing writer should fail forwarding");
|
||||
assert_eq!(error.kind(), io::ErrorKind::BrokenPipe);
|
||||
|
||||
for _ in 0..10 {
|
||||
if reader_dropped.load(Ordering::Acquire) {
|
||||
break;
|
||||
}
|
||||
tokio::task::yield_now().await;
|
||||
}
|
||||
assert!(reader_dropped.load(Ordering::Acquire));
|
||||
timeout(Duration::from_secs(5), reader_dropped.notified())
|
||||
.await
|
||||
.expect("reader should be dropped after the write error");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -125,11 +120,11 @@ async fn zero_delay_loopback_forwards_and_closes_active_sockets() -> anyhow::Res
|
||||
|
||||
struct PendingAfterChunkReader {
|
||||
chunks: VecDeque<Vec<u8>>,
|
||||
dropped: Arc<AtomicBool>,
|
||||
dropped: Arc<Notify>,
|
||||
}
|
||||
|
||||
impl PendingAfterChunkReader {
|
||||
fn new(dropped: Arc<AtomicBool>) -> Self {
|
||||
fn new(dropped: Arc<Notify>) -> Self {
|
||||
Self {
|
||||
chunks: VecDeque::from([b"x".to_vec()]),
|
||||
dropped,
|
||||
@@ -153,7 +148,7 @@ impl AsyncRead for PendingAfterChunkReader {
|
||||
|
||||
impl Drop for PendingAfterChunkReader {
|
||||
fn drop(&mut self) {
|
||||
self.dropped.store(true, Ordering::Release);
|
||||
self.dropped.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user