@@ -102,32 +102,38 @@ it.layer(NetService.layer)("NetService", (it) => {
102102 } ) ;
103103 } ) ;
104104
105- it . effect ( "preserves address-read context when closing an unusable reservation" , ( ) => {
106- const probe = NodeNet . createServer ( ) ;
107- const cause = new Error ( "close failed" ) ;
108- probe . unref = ( ( ) => probe ) as typeof probe . unref ;
109- probe . address = ( ( ) => null ) as typeof probe . address ;
110- probe . listen = ( ( _port : number , _host : string , listeningListener : ( ) => void ) => {
111- listeningListener ( ) ;
112- return probe ;
113- } ) as typeof probe . listen ;
114- probe . close = ( ( ) => {
115- probe . emit ( "error" , cause ) ;
116- return probe ;
117- } ) as typeof probe . close ;
118- const net = NetService . make ( { createServer : ( ) => probe } ) ;
105+ it . effect ( "preserves address context when an unusable reservation errors during close" , ( ) =>
106+ Effect . gen ( function * ( ) {
107+ for ( const invalidPort of [ null , 43.5 , 65_536 ] ) {
108+ const probe = NodeNet . createServer ( ) ;
109+ const cause = new Error ( "close failed" ) ;
110+ probe . unref = ( ( ) => probe ) as typeof probe . unref ;
111+ probe . address = ( ( ) => ( {
112+ address : "127.0.0.1" ,
113+ family : "IPv4" ,
114+ port : invalidPort ,
115+ } ) ) as unknown as typeof probe . address ;
116+ probe . listen = ( ( _port : number , _host : string , listeningListener : ( ) => void ) => {
117+ listeningListener ( ) ;
118+ return probe ;
119+ } ) as typeof probe . listen ;
120+ probe . close = ( ( ) => {
121+ probe . emit ( "error" , cause ) ;
122+ return probe ;
123+ } ) as typeof probe . close ;
124+ const net = NetService . make ( { createServer : ( ) => probe } ) ;
119125
120- return Effect . gen ( function * ( ) {
121- const error = yield * net . reserveLoopbackPort ( ) . pipe ( Effect . flip ) ;
126+ const error = yield * net . reserveLoopbackPort ( ) . pipe ( Effect . flip ) ;
122127
123- assert ( isLoopbackPortAddressUnavailableError ( error ) ) ;
124- assert . equal ( error . host , "127.0.0.1" ) ;
125- assert . equal ( error . address , null ) ;
126- assert . equal ( error . family , null ) ;
127- assert . equal ( error . port , null ) ;
128- assert . strictEqual ( error . cause , cause ) ;
129- } ) ;
130- } ) ;
128+ assert ( isLoopbackPortAddressUnavailableError ( error ) ) ;
129+ assert . equal ( error . host , "127.0.0.1" ) ;
130+ assert . equal ( error . address , "127.0.0.1" ) ;
131+ assert . equal ( error . family , "IPv4" ) ;
132+ assert . equal ( error . port , invalidPort ) ;
133+ assert . strictEqual ( error . cause , cause ) ;
134+ }
135+ } ) ,
136+ ) ;
131137
132138 it . effect ( "rejects missing and non-finite ports returned by the server" , ( ) =>
133139 Effect . gen ( function * ( ) {
0 commit comments