12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ use std:: task:: Poll ;
16
+
15
17
use bytes:: { Bytes , BytesMut } ;
18
+ use futures:: poll;
16
19
use nativelink_error:: { make_err, Code , Error , ResultExt } ;
17
20
use nativelink_util:: buf_channel:: make_buf_channel_pair;
18
21
use tokio:: try_join;
@@ -67,7 +70,7 @@ mod buf_channel_tests {
67
70
}
68
71
69
72
#[ tokio:: test]
70
- async fn consume_test ( ) -> Result < ( ) , Error > {
73
+ async fn consume_all_test ( ) -> Result < ( ) , Error > {
71
74
let ( mut tx, mut rx) = make_buf_channel_pair ( ) ;
72
75
let tx_fut = async move {
73
76
tx. send ( DATA1 . into ( ) ) . await ?;
@@ -91,7 +94,7 @@ mod buf_channel_tests {
91
94
/// Test to ensure data is optimized so that the exact same pointer is received
92
95
/// when calling `collect_all_with_size_hint` when a copy is not needed.
93
96
#[ tokio:: test]
94
- async fn consume_is_optimized_test ( ) -> Result < ( ) , Error > {
97
+ async fn consume_all_is_optimized_test ( ) -> Result < ( ) , Error > {
95
98
let ( mut tx, mut rx) = make_buf_channel_pair ( ) ;
96
99
let sent_data = Bytes :: from ( DATA1 ) ;
97
100
let send_data_ptr = sent_data. as_ptr ( ) ;
@@ -112,7 +115,7 @@ mod buf_channel_tests {
112
115
}
113
116
114
117
#[ tokio:: test]
115
- async fn take_test ( ) -> Result < ( ) , Error > {
118
+ async fn consume_some_test ( ) -> Result < ( ) , Error > {
116
119
let ( mut tx, mut rx) = make_buf_channel_pair ( ) ;
117
120
let tx_fut = async move {
118
121
tx. send ( DATA1 . into ( ) ) . await ?;
@@ -139,7 +142,7 @@ mod buf_channel_tests {
139
142
/// we don't need to concat the data together and instead return a view to
140
143
/// the original data instead of making a copy.
141
144
#[ tokio:: test]
142
- async fn take_optimized_test ( ) -> Result < ( ) , Error > {
145
+ async fn consume_some_optimized_test ( ) -> Result < ( ) , Error > {
143
146
let ( mut tx, mut rx) = make_buf_channel_pair ( ) ;
144
147
let first_chunk = Bytes :: from ( DATA1 ) ;
145
148
let first_chunk_ptr = first_chunk. as_ptr ( ) ;
@@ -159,6 +162,23 @@ mod buf_channel_tests {
159
162
Ok ( ( ) )
160
163
}
161
164
165
+ #[ tokio:: test]
166
+ async fn consume_some_reads_eof ( ) -> Result < ( ) , Error > {
167
+ let ( mut tx, mut rx) = make_buf_channel_pair ( ) ;
168
+ tx. send ( DATA1 . into ( ) ) . await ?;
169
+
170
+ let consume_fut = rx. consume ( Some ( DATA1 . len ( ) ) ) ;
171
+ tokio:: pin!( consume_fut) ;
172
+ assert_eq ! (
173
+ poll!( & mut consume_fut) ,
174
+ Poll :: Pending ,
175
+ "Consume should not have completed yet"
176
+ ) ;
177
+ tx. send_eof ( ) ?;
178
+ assert_eq ! ( consume_fut. await ?, Bytes :: from( DATA1 ) ) ;
179
+ Ok ( ( ) )
180
+ }
181
+
162
182
#[ tokio:: test]
163
183
async fn simple_stream_test ( ) -> Result < ( ) , Error > {
164
184
use futures:: StreamExt ;
@@ -245,7 +265,7 @@ mod buf_channel_tests {
245
265
rx. recv( ) . await ,
246
266
Err ( make_err!(
247
267
Code :: Internal ,
248
- "EOF received before sending EOF; sender was probably dropped "
268
+ "Sender dropped before sending EOF"
249
269
) )
250
270
) ;
251
271
Result :: < ( ) , Error > :: Ok ( ( ) )
0 commit comments