@@ -293,87 +293,81 @@ where
293
293
294
294
#[ cfg( test) ]
295
295
mod tests {
296
- use async_std:: { io, task} ;
297
296
use futures:: { channel:: mpsc, prelude:: * } ;
297
+ use tokio:: io:: { self , AsyncWriteExt } ;
298
298
299
299
use crate :: quicksink:: { make_sink, Action } ;
300
300
301
- #[ test]
302
- fn smoke_test ( ) {
303
- task:: block_on ( async {
304
- let sink = make_sink ( io:: stdout ( ) , |mut stdout, action| async move {
305
- match action {
306
- Action :: Send ( x) => stdout. write_all ( x) . await ?,
307
- Action :: Flush => stdout. flush ( ) . await ?,
308
- Action :: Close => stdout. close ( ) . await ?,
309
- }
310
- Ok :: < _ , io:: Error > ( stdout)
311
- } ) ;
301
+ #[ tokio:: test]
302
+ async fn smoke_test ( ) {
303
+ let sink = make_sink ( io:: stdout ( ) , |mut stdout, action| async move {
304
+ match action {
305
+ Action :: Send ( x) => stdout. write_all ( x) . await ?,
306
+ Action :: Flush => stdout. flush ( ) . await ?,
307
+ Action :: Close => stdout. shutdown ( ) . await ?,
308
+ }
309
+ Ok :: < _ , io:: Error > ( stdout)
310
+ } ) ;
312
311
313
- let values = vec ! [ Ok ( & b"hello\n " [ ..] ) , Ok ( & b"world\n " [ ..] ) ] ;
314
- assert ! ( stream:: iter( values) . forward( sink) . await . is_ok( ) )
315
- } )
312
+ let values = vec ! [ Ok ( & b"hello\n " [ ..] ) , Ok ( & b"world\n " [ ..] ) ] ;
313
+ assert ! ( stream:: iter( values) . forward( sink) . await . is_ok( ) )
316
314
}
317
315
318
- #[ test]
319
- fn replay ( ) {
320
- task:: block_on ( async {
321
- let ( tx, rx) = mpsc:: channel ( 5 ) ;
316
+ #[ tokio:: test]
317
+ async fn replay ( ) {
318
+ let ( tx, rx) = mpsc:: channel ( 5 ) ;
322
319
323
- let sink = make_sink ( tx, |mut tx, action| async move {
324
- tx. send ( action. clone ( ) ) . await ?;
325
- if action == Action :: Close {
326
- tx. close ( ) . await ?
327
- }
328
- Ok :: < _ , mpsc:: SendError > ( tx)
329
- } ) ;
320
+ let sink = make_sink ( tx, |mut tx, action| async move {
321
+ tx. send ( action. clone ( ) ) . await ?;
322
+ if action == Action :: Close {
323
+ tx. close ( ) . await ?
324
+ }
325
+ Ok :: < _ , mpsc:: SendError > ( tx)
326
+ } ) ;
330
327
331
- futures:: pin_mut!( sink) ;
328
+ futures:: pin_mut!( sink) ;
332
329
333
- let expected = [
334
- Action :: Send ( "hello\n " ) ,
335
- Action :: Flush ,
336
- Action :: Send ( "world\n " ) ,
337
- Action :: Flush ,
338
- Action :: Close ,
339
- ] ;
330
+ let expected = [
331
+ Action :: Send ( "hello\n " ) ,
332
+ Action :: Flush ,
333
+ Action :: Send ( "world\n " ) ,
334
+ Action :: Flush ,
335
+ Action :: Close ,
336
+ ] ;
340
337
341
- for & item in & [ "hello\n " , "world\n " ] {
342
- sink. send ( item) . await . unwrap ( )
343
- }
338
+ for & item in & [ "hello\n " , "world\n " ] {
339
+ sink. send ( item) . await . unwrap ( )
340
+ }
344
341
345
- sink. close ( ) . await . unwrap ( ) ;
342
+ sink. close ( ) . await . unwrap ( ) ;
346
343
347
- let actual = rx. collect :: < Vec < _ > > ( ) . await ;
344
+ let actual = rx. collect :: < Vec < _ > > ( ) . await ;
348
345
349
- assert_eq ! ( & expected[ ..] , & actual[ ..] )
350
- } ) ;
346
+ assert_eq ! ( & expected[ ..] , & actual[ ..] )
351
347
}
352
348
353
- #[ test]
354
- fn error_does_not_panic ( ) {
355
- task:: block_on ( async {
356
- let sink = make_sink ( io:: stdout ( ) , |mut _stdout, _action| async move {
357
- Err ( io:: Error :: other ( "oh no" ) )
358
- } ) ;
349
+ #[ tokio:: test]
350
+ async fn error_does_not_panic ( ) {
351
+ let sink = make_sink ( io:: stdout ( ) , |mut _stdout, _action| async move {
352
+ Err ( io:: Error :: other ( "oh no" ) )
353
+ } ) ;
359
354
360
- futures:: pin_mut!( sink) ;
355
+ futures:: pin_mut!( sink) ;
361
356
362
- let result = sink. send ( "hello" ) . await ;
363
- match result {
364
- Err ( crate :: quicksink:: Error :: Send ( e) ) => {
365
- assert_eq ! ( e. kind( ) , io:: ErrorKind :: Other ) ;
366
- assert_eq ! ( e. to_string( ) , "oh no" )
367
- }
368
- _ => panic ! ( "unexpected result: {result:?}" ) ,
369
- } ;
357
+ let result = sink. send ( "hello" ) . await ;
358
+ match result {
359
+ Err ( crate :: quicksink:: Error :: Send ( e) ) => {
360
+ assert_eq ! ( e. kind( ) , io:: ErrorKind :: Other ) ;
361
+ assert_eq ! ( e. to_string( ) , "oh no" )
362
+ }
363
+ _ => panic ! ( "unexpected result: {result:?}" ) ,
364
+ } ;
370
365
371
- // Call send again, expect not to panic.
372
- let result = sink. send ( "hello" ) . await ;
373
- match result {
374
- Err ( crate :: quicksink:: Error :: Closed ) => { }
375
- _ => panic ! ( "unexpected result: {result:?}" ) ,
376
- } ;
377
- } )
366
+ // Call send again, expect not to panic.
367
+ let result = sink. send ( "hello" ) . await ;
368
+ match result {
369
+ Err ( crate :: quicksink:: Error :: Closed ) => { }
370
+ _ => panic ! ( "unexpected result: {result:?}" ) ,
371
+ } ;
378
372
}
379
373
}
0 commit comments