@@ -11,26 +11,31 @@ if (!common.hasIPv6) {
1111
1212const client = dgram . createSocket ( 'udp6' ) ;
1313
14- const toSend = [ new Buffer ( 256 ) , new Buffer ( 256 ) , new Buffer ( 256 ) , 'hello' ] ;
14+ const toSend = [ Buffer . alloc ( 256 , 'x' ) ,
15+ Buffer . alloc ( 256 , 'y' ) ,
16+ Buffer . alloc ( 256 , 'z' ) ,
17+ 'hello' ] ;
1518
16- toSend [ 0 ] . fill ( 'x' ) ;
17- toSend [ 1 ] . fill ( 'y' ) ;
18- toSend [ 2 ] . fill ( 'z' ) ;
19+ const received = [ ] ;
1920
20- client . on ( 'listening' , function ( ) {
21+ client . on ( 'listening' , common . mustCall ( ( ) => {
2122 client . send ( toSend [ 0 ] , 0 , toSend [ 0 ] . length , common . PORT ) ;
2223 client . send ( toSend [ 1 ] , common . PORT ) ;
2324 client . send ( [ toSend [ 2 ] ] , common . PORT ) ;
2425 client . send ( toSend [ 3 ] , 0 , toSend [ 3 ] . length , common . PORT ) ;
25- } ) ;
26+ } ) ) ;
2627
27- client . on ( 'message' , function ( buf , info ) {
28- const expected = toSend . shift ( ) . toString ( ) ;
29- assert . ok ( buf . toString ( ) === expected , 'message was received correctly' ) ;
28+ client . on ( 'message' , common . mustCall ( ( buf , info ) => {
29+ received . push ( buf . toString ( ) ) ;
3030
31- if ( toSend . length === 0 ) {
31+ if ( received . length === toSend . length ) {
32+ // The replies may arrive out of order -> sort them before checking.
33+ received . sort ( ) ;
34+
35+ const expected = toSend . map ( String ) . sort ( ) ;
36+ assert . deepStrictEqual ( received , expected ) ;
3237 client . close ( ) ;
3338 }
34- } ) ;
39+ } , toSend . length ) ) ;
3540
3641client . bind ( common . PORT ) ;
0 commit comments