From 49609d073f9f8e39e5583ba3f5d459b100392af5 Mon Sep 17 00:00:00 2001 From: Emil Loer Date: Tue, 4 Jun 2024 23:42:42 +0200 Subject: [PATCH] test: make `Spawn` forward `size_hint` (#6607) --- tokio-test/src/task.rs | 4 ++++ tokio-test/tests/task.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tokio-test/tests/task.rs diff --git a/tokio-test/src/task.rs b/tokio-test/src/task.rs index 812f908ac..2e646d44b 100644 --- a/tokio-test/src/task.rs +++ b/tokio-test/src/task.rs @@ -148,6 +148,10 @@ impl Stream for Spawn { fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.future.as_mut().poll_next(cx) } + + fn size_hint(&self) -> (usize, Option) { + self.future.size_hint() + } } impl MockTask { diff --git a/tokio-test/tests/task.rs b/tokio-test/tests/task.rs new file mode 100644 index 000000000..a464bf9b7 --- /dev/null +++ b/tokio-test/tests/task.rs @@ -0,0 +1,25 @@ +use std::pin::Pin; +use std::task::{Context, Poll}; +use tokio_stream::Stream; +use tokio_test::task; + +/// A [`Stream`] that has a stub size hint. +struct SizedStream; + +impl Stream for SizedStream { + type Item = (); + + fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + Poll::Pending + } + + fn size_hint(&self) -> (usize, Option) { + (100, Some(200)) + } +} + +#[test] +fn test_spawn_stream_size_hint() { + let spawn = task::spawn(SizedStream); + assert_eq!(spawn.size_hint(), (100, Some(200))); +}