mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
test: make Spawn forward size_hint (#6607)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
Reference in New Issue
Block a user