test: make Spawn forward size_hint (#6607)

This commit is contained in:
Emil Loer
2024-06-04 23:42:42 +02:00
committed by GitHub
parent a91d43823c
commit 49609d073f
2 changed files with 29 additions and 0 deletions
+4
View File
@@ -148,6 +148,10 @@ impl<T: Stream> Stream for Spawn<T> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.future.as_mut().poll_next(cx)
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.future.size_hint()
}
}
impl MockTask {
+25
View File
@@ -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<Option<Self::Item>> {
Poll::Pending
}
fn size_hint(&self) -> (usize, Option<usize>) {
(100, Some(200))
}
}
#[test]
fn test_spawn_stream_size_hint() {
let spawn = task::spawn(SizedStream);
assert_eq!(spawn.size_hint(), (100, Some(200)));
}