@@ -11,26 +11,31 @@ if (!common.hasIPv6) {
11
11
12
12
const client = dgram . createSocket ( 'udp6' ) ;
13
13
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' ] ;
15
18
16
- toSend [ 0 ] . fill ( 'x' ) ;
17
- toSend [ 1 ] . fill ( 'y' ) ;
18
- toSend [ 2 ] . fill ( 'z' ) ;
19
+ const received = [ ] ;
19
20
20
- client . on ( 'listening' , function ( ) {
21
+ client . on ( 'listening' , common . mustCall ( ( ) => {
21
22
client . send ( toSend [ 0 ] , 0 , toSend [ 0 ] . length , common . PORT ) ;
22
23
client . send ( toSend [ 1 ] , common . PORT ) ;
23
24
client . send ( [ toSend [ 2 ] ] , common . PORT ) ;
24
25
client . send ( toSend [ 3 ] , 0 , toSend [ 3 ] . length , common . PORT ) ;
25
- } ) ;
26
+ } ) ) ;
26
27
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 ( ) ) ;
30
30
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 ) ;
32
37
client . close ( ) ;
33
38
}
34
- } ) ;
39
+ } , toSend . length ) ) ;
35
40
36
41
client . bind ( common . PORT ) ;
0 commit comments