@@ -3,49 +3,51 @@ const common = require('../common');
3
3
const assert = require ( 'assert' ) ;
4
4
const dgram = require ( 'dgram' ) ;
5
5
6
- const port = common . PORT ;
7
6
const buf = Buffer . from ( 'test' ) ;
8
- const client = dgram . createSocket ( 'udp4' ) ;
9
7
10
8
const onMessage = common . mustCall ( ( err , bytes ) => {
11
9
assert . ifError ( err ) ;
12
10
assert . strictEqual ( bytes , buf . length ) ;
13
11
} , 6 ) ;
14
12
15
- // valid address: false
16
- client . send ( buf , port , false , onMessage ) ;
13
+ const expectedError =
14
+ / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : a d d r e s s m u s t b e a n o n e m p t y s t r i n g o r f a l s y $ / ;
17
15
18
- // valid address: empty string
19
- client . send ( buf , port , '' , onMessage ) ;
16
+ const client = dgram . createSocket ( 'udp4' ) . bind ( 0 , ( ) => {
17
+ const port = client . address ( ) . port ;
20
18
21
- // valid address: null
22
- client . send ( buf , port , null , onMessage ) ;
19
+ // valid address: false
20
+ client . send ( buf , port , false , onMessage ) ;
23
21
24
- // valid address: 0
25
- client . send ( buf , port , 0 , onMessage ) ;
22
+ // valid address: empty string
23
+ client . send ( buf , port , '' , onMessage ) ;
26
24
27
- // valid address: undefined
28
- client . send ( buf , port , undefined , onMessage ) ;
25
+ // valid address: null
26
+ client . send ( buf , port , null , onMessage ) ;
29
27
30
- // valid address: not provided
31
- client . send ( buf , port , onMessage ) ;
28
+ // valid address: 0
29
+ client . send ( buf , port , 0 , onMessage ) ;
32
30
33
- const expectedError =
34
- / ^ T y p e E r r o r : I n v a l i d a r g u m e n t s : a d d r e s s m u s t b e a n o n e m p t y s t r i n g o r f a l s y $ / ;
31
+ // valid address: undefined
32
+ client . send ( buf , port , undefined , onMessage ) ;
33
+
34
+ // valid address: not provided
35
+ client . send ( buf , port , onMessage ) ;
35
36
36
- // invalid address: object
37
- assert . throws ( ( ) => {
38
- client . send ( buf , port , [ ] ) ;
39
- } , expectedError ) ;
37
+ // invalid address: object
38
+ assert . throws ( ( ) => {
39
+ client . send ( buf , port , [ ] ) ;
40
+ } , expectedError ) ;
40
41
41
- // invalid address: nonzero number
42
- assert . throws ( ( ) => {
43
- client . send ( buf , port , 1 ) ;
44
- } , expectedError ) ;
42
+ // invalid address: nonzero number
43
+ assert . throws ( ( ) => {
44
+ client . send ( buf , port , 1 ) ;
45
+ } , expectedError ) ;
45
46
46
- // invalid address: true
47
- assert . throws ( ( ) => {
48
- client . send ( buf , port , true ) ;
49
- } , expectedError ) ;
47
+ // invalid address: true
48
+ assert . throws ( ( ) => {
49
+ client . send ( buf , port , true ) ;
50
+ } , expectedError ) ;
51
+ } ) ;
50
52
51
53
client . unref ( ) ;
0 commit comments