From d78b24b6310af6c9ec06b67356c85a1bba1f0cac Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Fri, 8 Oct 2021 21:28:43 -0700 Subject: [PATCH] Assert that poll_expired yields None when DelayQueue is empty --- tarpc/src/server/in_flight_requests.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tarpc/src/server/in_flight_requests.rs b/tarpc/src/server/in_flight_requests.rs index 67817e2..581eac3 100644 --- a/tarpc/src/server/in_flight_requests.rs +++ b/tarpc/src/server/in_flight_requests.rs @@ -185,11 +185,26 @@ mod tests { async fn remove_request_doesnt_abort() { let mut in_flight_requests = InFlightRequests::default(); let abort_registration = in_flight_requests - .start_request(0, SystemTime::now(), Span::current()) + .start_request( + 0, + SystemTime::now() + std::time::Duration::from_secs(10), + Span::current(), + ) .unwrap(); let mut abortable_future = Box::new(Abortable::new(pending::<()>(), abort_registration)); + // Precondition: Pending expiration + assert_matches!( + in_flight_requests.poll_expired(&mut noop_context()), + Poll::Pending + ); + assert_matches!(in_flight_requests.remove_request(0), Some(_)); + // Postcondition: No pending expirations + assert_matches!( + in_flight_requests.poll_expired(&mut noop_context()), + Poll::Ready(None) + ); assert_matches!( abortable_future.poll_unpin(&mut noop_context()), Poll::Pending