|
1 | 1 | use futures::pin_mut; |
2 | 2 | use futures_test::task::noop_context; |
3 | | -use std::{future::Future, task::Poll}; |
| 3 | +use std::task::Poll; |
4 | 4 | use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}; |
5 | | -use tokio_test::{assert_pending, assert_ready_err}; |
| 5 | +use tokio_test::assert_pending; |
6 | 6 | use tokio_test::task::spawn; |
7 | 7 | use tokio_util::io::simplex; |
8 | 8 |
|
@@ -58,30 +58,25 @@ fn multi_thread() { |
58 | 58 | jh1.join().unwrap(); |
59 | 59 | } |
60 | 60 |
|
61 | | -/// The `Sender` should returns error if the read half has been dropped. |
| 61 | +/// The `Sender` should returns error if the `Receiver` has been dropped. |
62 | 62 | #[tokio::test] |
63 | 63 | async fn drop_receiver_0() { |
64 | | - const MSG: &[u8] = b"Hello, world!"; |
65 | | - |
66 | 64 | let (mut tx, rx) = simplex::new(32); |
67 | 65 | drop(rx); |
68 | 66 |
|
69 | | - tx.write_all(MSG).await.unwrap_err(); |
| 67 | + tx.write_u8(1).await.unwrap_err(); |
70 | 68 | } |
71 | 69 |
|
72 | | -/// The `Sender` should be woken up if the read half is dropped. |
| 70 | +/// The `Sender` should be woken up if the `Receiver` has been dropped. |
73 | 71 | #[tokio::test] |
74 | 72 | async fn drop_receiver_1() { |
75 | | - const MSG: &[u8] = b"Hello, world!"; |
76 | | - |
77 | | - // only set `1` capacity to make sure the write half will be blocked |
78 | | - // by the read half |
79 | 73 | let (mut tx, rx) = simplex::new(1); |
80 | | - let fut = tx.write_all(MSG); |
81 | | - pin_mut!(fut); |
82 | | - assert_pending!(fut.as_mut().poll(&mut noop_context())); |
| 74 | + let mut write_task = spawn(tx.write_u16(1)); |
| 75 | + assert_pending!(write_task.poll()); |
| 76 | + |
| 77 | + assert!(!write_task.is_woken()); |
83 | 78 | drop(rx); |
84 | | - assert_ready_err!(fut.poll(&mut noop_context())); |
| 79 | + assert!(write_task.is_woken()); |
85 | 80 | } |
86 | 81 |
|
87 | 82 | /// The `Receiver` should returns error if: |
|
0 commit comments