@@ -185,18 +185,19 @@ effectIt.effect("preserves explicit loopback hosts and bounds wildcard rewrites"
185185effectIt . effect ( "projects configured paths independently for simultaneous subscribers" , ( ) => {
186186 const docsUrl = `http://localhost:${ LSOF_TEST_PORT } /docs` ;
187187 const adminUrl = `http://localhost:${ LSOF_TEST_PORT } /admin` ;
188+ let ready = true ;
188189 const fetchFn = ( ( input : Parameters < typeof globalThis . fetch > [ 0 ] ) => {
189190 const url = String ( input ) ;
190191 return Promise . resolve (
191- url === docsUrl || url === adminUrl
192+ ready && ( url === docsUrl || url === adminUrl )
192193 ? new Response ( "app" , { headers : { "content-type" : "text/html" } } )
193194 : new Response ( "not found" , { status : 404 } ) ,
194195 ) ;
195196 } ) as typeof globalThis . fetch ;
196197 const layer = layerLsofScanner ( { pid : ( ) => 1234 , fetch : fetchFn } ) ;
197198
198199 return Effect . gen ( function * ( ) {
199- const scanner = yield * PortScanner . PortDiscovery ;
200+ const scanner = yield * ownedScanner ( ) ;
200201 const docsSnapshots : ReadonlyArray < DiscoveredLocalServer > [ ] = [ ] ;
201202 const adminSnapshots : ReadonlyArray < DiscoveredLocalServer > [ ] = [ ] ;
202203 yield * scanner . subscribe ( { configuredUrls : [ docsUrl ] , initialSnapshot : [ ] } , ( servers ) =>
@@ -209,6 +210,11 @@ effectIt.effect("projects configured paths independently for simultaneous subscr
209210
210211 expect ( docsSnapshots . at ( - 1 ) ?. [ 0 ] ?. url ) . toBe ( docsUrl ) ;
211212 expect ( adminSnapshots . at ( - 1 ) ?. [ 0 ] ?. url ) . toBe ( adminUrl ) ;
213+
214+ ready = false ;
215+ yield * TestClock . adjust ( Duration . seconds ( 15 ) ) ;
216+ expect ( docsSnapshots . at ( - 1 ) ?. [ 0 ] ?. url ) . toBe ( docsUrl ) ;
217+ expect ( adminSnapshots . at ( - 1 ) ?. [ 0 ] ?. url ) . toBe ( adminUrl ) ;
212218 } ) . pipe ( Effect . scoped , Effect . provide ( layer ) ) ;
213219} ) ;
214220
@@ -300,25 +306,43 @@ effectIt.effect("uses the current configured fragment when readiness comes from
300306 } ) . pipe ( Effect . provide ( layer ) ) ;
301307} ) ;
302308
303- effectIt . effect ( "probes only a configured HTTPS URL and does not follow its redirects" , ( ) => {
304- const configuredUrl = `https://localhost:${ LSOF_TEST_PORT } /app` ;
305- const requests : Array < readonly [ string , string | undefined ] > = [ ] ;
306- const fetchFn = ( async (
307- input : Parameters < typeof globalThis . fetch > [ 0 ] ,
308- init ?: Parameters < typeof globalThis . fetch > [ 1 ] ,
309- ) => {
310- requests . push ( [ String ( input ) , init ?. redirect ] ) ;
311- return new Response ( null , { status : 302 , headers : { location : "https://example.com" } } ) ;
312- } ) as typeof globalThis . fetch ;
313- const layer = layerLsofScanner ( { pid : ( ) => 1234 , fetch : fetchFn } ) ;
309+ effectIt . effect (
310+ "probes only a configured HTTPS URL, keeps it for an owned listener when the check fails, and does not follow redirects" ,
311+ ( ) => {
312+ const configuredUrl = `https://localhost:${ LSOF_TEST_PORT } /app` ;
313+ const requests : Array < readonly [ string , string | undefined ] > = [ ] ;
314+ let respond = async ( ) =>
315+ new Response ( null , { status : 302 , headers : { location : "https://example.com" } } ) ;
316+ const fetchFn = ( async (
317+ input : Parameters < typeof globalThis . fetch > [ 0 ] ,
318+ init ?: Parameters < typeof globalThis . fetch > [ 1 ] ,
319+ ) => {
320+ requests . push ( [ String ( input ) , init ?. redirect ] ) ;
321+ return respond ( ) ;
322+ } ) as typeof globalThis . fetch ;
323+ const layer = layerLsofScanner ( { pid : ( ) => 1234 , fetch : fetchFn } ) ;
314324
315- return Effect . gen ( function * ( ) {
316- const scanner = yield * ownedScanner ( ) ;
317- const servers = yield * scanner . scan ( [ configuredUrl ] ) ;
318- expect ( servers ) . toMatchObject ( [ { pid : 1234 , url : configuredUrl } ] ) ;
319- expect ( requests ) . toEqual ( [ [ configuredUrl , "manual" ] ] ) ;
320- } ) . pipe ( Effect . provide ( layer ) ) ;
321- } ) ;
325+ return Effect . gen ( function * ( ) {
326+ const scanner = yield * ownedScanner ( ) ;
327+ expect ( yield * scanner . scan ( [ configuredUrl ] ) ) . toMatchObject ( [
328+ { pid : 1234 , url : configuredUrl } ,
329+ ] ) ;
330+
331+ respond = async ( ) => new Response ( "unavailable" , { status : 503 } ) ;
332+ yield * TestClock . adjust ( Duration . seconds ( 15 ) ) ;
333+ expect ( yield * scanner . scan ( [ configuredUrl ] ) ) . toMatchObject ( [
334+ { pid : 1234 , url : configuredUrl } ,
335+ ] ) ;
336+
337+ respond = ( ) => Promise . reject ( new TypeError ( "fetch failed" ) ) ;
338+ yield * TestClock . adjust ( Duration . seconds ( 15 ) ) ;
339+ expect ( yield * scanner . scan ( [ configuredUrl ] ) ) . toMatchObject ( [
340+ { pid : 1234 , url : configuredUrl } ,
341+ ] ) ;
342+ expect ( requests ) . toEqual ( Array . from ( { length : 3 } , ( ) => [ configuredUrl , "manual" ] ) ) ;
343+ } ) . pipe ( Effect . provide ( layer ) ) ;
344+ } ,
345+ ) ;
322346
323347effectIt . effect ( "discovers owned listeners without sending HTTP or TLS probes" , ( ) => {
324348 const owned = `p1234\ncnode\nn[::1]:${ LSOF_TEST_PORT } \n` ;
0 commit comments