| ... | @@ -7,7 +7,6 @@ import { | ... | @@ -7,7 +7,6 @@ import { |
| 7 | type DiscoveredLocalServer, | 7 | type DiscoveredLocalServer, |
| 8 | } from "@t3tools/contracts"; | 8 | } from "@t3tools/contracts"; |
| 9 | import * as HostProcess from "@t3tools/shared/HostProcess"; | 9 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 10 | import * as Net from "@t3tools/shared/Net"; | | |
| 11 | import * as Cause from "effect/Cause"; | 10 | import * as Cause from "effect/Cause"; |
| 12 | import * as Clock from "effect/Clock"; | 11 | import * as Clock from "effect/Clock"; |
| 13 | import * as Duration from "effect/Duration"; | 12 | import * as Duration from "effect/Duration"; |
| ... | @@ -44,17 +43,7 @@ const layerTestProcessRunner = Layer.succeed(ProcessRunner.ProcessRunner, { | ... | @@ -44,17 +43,7 @@ const layerTestProcessRunner = Layer.succeed(ProcessRunner.ProcessRunner, { |
| 44 | run: processProbeFailure, | 43 | run: processProbeFailure, |
| 45 | }); | 44 | }); |
| 46 | | 45 | |
| 47 | let integrationListeningPort: number | null = null; | 46 | /** A host without `/proc`, so a missing `lsof` leaves only configured URLs. */ |
| 48 | | | |
| 49 | const layerTestIntegrationNet = Layer.succeed(Net.NetService, { | | |
| 50 | canListenOnHost: () => Effect.succeed(true), | | |
| 51 | isPortAvailableOnLoopback: (port) => Effect.sync(() => port !== integrationListeningPort), | | |
| 52 | hasListenerOnHost: (port) => Effect.sync(() => port === integrationListeningPort), | | |
| 53 | reserveLoopbackPort: () => Effect.succeed(40_000), | | |
| 54 | findAvailablePort: (preferred) => Effect.succeed(preferred), | | |
| 55 | }); | | |
| 56 | | | |
| 57 | /** A host without `/proc`, so a missing `lsof` falls back to common ports. */ | | |
| 58 | const layerNoProc = FileSystem.layerNoop({}); | 47 | const layerNoProc = FileSystem.layerNoop({}); |
| 59 | | 48 | |
| 60 | const layerProbeFailure = ( | 49 | const layerProbeFailure = ( |
| ... | @@ -67,13 +56,6 @@ const layerProbeFailure = ( | ... | @@ -67,13 +56,6 @@ const layerProbeFailure = ( |
| 67 | Layer.mergeAll( | 56 | Layer.mergeAll( |
| 68 | fileSystem, | 57 | fileSystem, |
| 69 | Layer.succeed(ProcessRunner.ProcessRunner, { run }), | 58 | Layer.succeed(ProcessRunner.ProcessRunner, { run }), |
| 70 | Layer.succeed(Net.NetService, { | | |
| 71 | canListenOnHost: () => Effect.succeed(true), | | |
| 72 | isPortAvailableOnLoopback: () => Effect.succeed(true), | | |
| 73 | hasListenerOnHost: () => Effect.succeed(false), | | |
| 74 | reserveLoopbackPort: () => Effect.succeed(40_000), | | |
| 75 | findAvailablePort: (preferred) => Effect.succeed(preferred), | | |
| 76 | }), | | |
| 77 | Layer.succeed(HostProcess.Platform, "linux"), | 59 | Layer.succeed(HostProcess.Platform, "linux"), |
| 78 | FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetch))), | 60 | FetchHttpClient.layer.pipe(Layer.provide(Layer.succeed(FetchHttpClient.Fetch, fetch))), |
| 79 | ), | 61 | ), |
| ... | @@ -85,7 +67,6 @@ const layerTestPortDiscovery = PortScanner.layer.pipe( | ... | @@ -85,7 +67,6 @@ const layerTestPortDiscovery = PortScanner.layer.pipe( |
| 85 | Layer.mergeAll( | 67 | Layer.mergeAll( |
| 86 | layerNoProc, | 68 | layerNoProc, |
| 87 | layerTestProcessRunner, | 69 | layerTestProcessRunner, |
| 88 | layerTestIntegrationNet, | | |
| 89 | Layer.succeed(HostProcess.Platform, "win32"), | 70 | Layer.succeed(HostProcess.Platform, "win32"), |
| 90 | FetchHttpClient.layer, | 71 | FetchHttpClient.layer, |
| 91 | ), | 72 | ), |
| ... | @@ -94,9 +75,20 @@ const layerTestPortDiscovery = PortScanner.layer.pipe( | ... | @@ -94,9 +75,20 @@ const layerTestPortDiscovery = PortScanner.layer.pipe( |
| 94 | | 75 | |
| 95 | const LSOF_TEST_PORT = 43_123; | 76 | const LSOF_TEST_PORT = 43_123; |
| 96 | | 77 | |
| | 78 | /** The scanner with `processIds` registered to a T3 terminal, so their listeners get probes. */ |
| | 79 | const ownedScanner = (processIds: ReadonlyArray<number> = [1234]) => |
| | 80 | Effect.tap(PortScanner.PortDiscovery, (scanner) => |
| | 81 | scanner.registerTerminalProcesses({ |
| | 82 | threadId: "scanner-thread", |
| | 83 | terminalId: "scanner-terminal", |
| | 84 | processIds, |
| | 85 | }), |
| | 86 | ); |
| | 87 | |
| 97 | const layerLsofScanner = (input: { | 88 | const layerLsofScanner = (input: { |
| 98 | readonly pid: () => number; | 89 | readonly pid: () => number; |
| 99 | readonly fetch: typeof globalThis.fetch; | 90 | readonly fetch: typeof globalThis.fetch; |
| | 91 | readonly stdout?: () => string; |
| 100 | }) => | 92 | }) => |
| 101 | PortScanner.layer.pipe( | 93 | PortScanner.layer.pipe( |
| 102 | Layer.provide( | 94 | Layer.provide( |
| ... | @@ -105,7 +97,7 @@ const layerLsofScanner = (input: { | ... | @@ -105,7 +97,7 @@ const layerLsofScanner = (input: { |
| 105 | Layer.succeed(ProcessRunner.ProcessRunner, { | 97 | Layer.succeed(ProcessRunner.ProcessRunner, { |
| 106 | run: () => | 98 | run: () => |
| 107 | Effect.succeed({ | 99 | Effect.succeed({ |
| 108 | stdout: `p${input.pid()}\ncnode\nn*:${LSOF_TEST_PORT}\n`, | 100 | stdout: input.stdout?.() ?? `p${input.pid()}\ncnode\nn*:${LSOF_TEST_PORT}\n`, |
| 109 | stderr: "", | 101 | stderr: "", |
| 110 | code: null, | 102 | code: null, |
| 111 | timedOut: false, | 103 | timedOut: false, |
| ... | @@ -115,13 +107,6 @@ const layerLsofScanner = (input: { | ... | @@ -115,13 +107,6 @@ const layerLsofScanner = (input: { |
| 115 | stderrInvalidUtf8: false, | 107 | stderrInvalidUtf8: false, |
| 116 | }), | 108 | }), |
| 117 | }), | 109 | }), |
| 118 | Layer.succeed(Net.NetService, { | | |
| 119 | canListenOnHost: () => Effect.succeed(true), | | |
| 120 | isPortAvailableOnLoopback: () => Effect.succeed(true), | | |
| 121 | hasListenerOnHost: () => Effect.succeed(false), | | |
| 122 | reserveLoopbackPort: () => Effect.succeed(40_000), | | |
| 123 | findAvailablePort: (preferred) => Effect.succeed(preferred), | | |
| 124 | }), | | |
| 125 | Layer.succeed(HostProcess.Platform, "linux"), | 110 | Layer.succeed(HostProcess.Platform, "linux"), |
| 126 | FetchHttpClient.layer.pipe( | 111 | FetchHttpClient.layer.pipe( |
| 127 | Layer.provide(Layer.succeed(FetchHttpClient.Fetch, input.fetch)), | 112 | Layer.provide(Layer.succeed(FetchHttpClient.Fetch, input.fetch)), |
| ... | @@ -153,73 +138,45 @@ const closeServer = (server: NodeNet.Server): Effect.Effect<void> => | ... | @@ -153,73 +138,45 @@ const closeServer = (server: NodeNet.Server): Effect.Effect<void> => |
| 153 | }); | 138 | }); |
| 154 | | 139 | |
| 155 | const openCommonDevServer = Effect.fn("PortScannerTest.openCommonDevServer")(function* ( | 140 | const openCommonDevServer = Effect.fn("PortScannerTest.openCommonDevServer")(function* ( |
| 156 | ports: ReadonlyArray<number>, | | |
| 157 | onConnection: (socket: NodeNet.Socket) => void, | 141 | onConnection: (socket: NodeNet.Socket) => void, |
| 158 | ) { | 142 | ) { |
| 159 | for (const port of ports) { | 143 | const server = yield* openServer(0, onConnection); |
| 160 | const server = yield* openServer(port, onConnection); | 144 | const address = server?.address(); |
| 161 | if (server !== null) return { port, server }; | 145 | if (!server || !address || typeof address === "string") { |
| | 146 | return yield* Effect.die(new Error("Could not open the preview scanner test listener")); |
| 162 | } | 147 | } |
| 163 | return yield* Effect.die( | 148 | return { port: address.port, server }; |
| 164 | new Error("No common development port was available for the preview scanner test"), | | |
| 165 | ); | | |
| 166 | }); | 149 | }); |
| 167 | | 150 | |
| 168 | const commonDevServer = Effect.acquireRelease( | 151 | const commonDevServer = Effect.acquireRelease( |
| 169 | openCommonDevServer(PortScanner.COMMON_DEV_PORTS, (socket) => { | 152 | openCommonDevServer((socket) => { |
| 170 | socket.once("data", () => { | 153 | socket.once("data", () => { |
| 171 | socket.end("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 5\r\n\r\nhello"); | 154 | socket.end("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 5\r\n\r\nhello"); |
| 172 | }); | 155 | }); |
| 173 | }).pipe( | 156 | }), |
| 174 | Effect.tap(({ port }) => | 157 | ({ server }) => closeServer(server), |
| 175 | Effect.sync(() => { | | |
| 176 | integrationListeningPort = port; | | |
| 177 | }), | | |
| 178 | ), | | |
| 179 | ), | | |
| 180 | ({ server }) => | | |
| 181 | closeServer(server).pipe( | | |
| 182 | Effect.ensuring( | | |
| 183 | Effect.sync(() => { | | |
| 184 | integrationListeningPort = null; | | |
| 185 | }), | | |
| 186 | ), | | |
| 187 | ), | | |
| 188 | ); | 158 | ); |
| 189 | | 159 | |
| 190 | const commonNonHttpServer = Effect.acquireRelease( | 160 | const commonNonHttpServer = Effect.acquireRelease( |
| 191 | openCommonDevServer(PortScanner.COMMON_DEV_PORTS.toReversed(), (socket) => { | 161 | openCommonDevServer((socket) => { |
| 192 | socket.on("error", () => undefined); | 162 | socket.on("error", () => undefined); |
| 193 | socket.once("data", () => socket.end("MYSQL\r\n\r\n")); | 163 | socket.once("data", () => socket.end("MYSQL\r\n\r\n")); |
| 194 | }).pipe( | 164 | }), |
| 195 | Effect.tap(({ port }) => | 165 | ({ server }) => closeServer(server), |
| 196 | Effect.sync(() => { | | |
| 197 | integrationListeningPort = port; | | |
| 198 | }), | | |
| 199 | ), | | |
| 200 | ), | | |
| 201 | ({ server }) => | | |
| 202 | closeServer(server).pipe( | | |
| 203 | Effect.ensuring( | | |
| 204 | Effect.sync(() => { | | |
| 205 | integrationListeningPort = null; | | |
| 206 | }), | | |
| 207 | ), | | |
| 208 | ), | | |
| 209 | ); | 166 | ); |
| 210 | | 167 | |
| 211 | /** | 168 | /** |
| 212 | * Integration tests against a real TCP listener. We provide the Windows host | 169 | * Integration tests against a real TCP listener. We provide the Windows host |
| 213 | * platform so the tests exercise the TCP-probe fallback without depending on | 170 | * platform with a failing listener probe so the tests exercise configured URLs |
| 214 | * `lsof` being installed. | 171 | * without depending on `lsof` being installed. |
| 215 | */ | 172 | */ |
| 216 | effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (TCP probe fallback)", (it) => { | 173 | effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (configured URLs)", (it) => { |
| 217 | it.effect( | 174 | it.effect( |
| 218 | "scan() returns an HTTP server we just opened on a curated dev port", | 175 | "scan() returns a configured HTTP server we just opened", |
| 219 | Effect.fn("PortScannerTest.scanFindsCommonDevServer")(function* () { | 176 | Effect.fn("PortScannerTest.scanFindsCommonDevServer")(function* () { |
| 220 | const { port } = yield* commonDevServer; | 177 | const { port } = yield* commonDevServer; |
| 221 | const scanner = yield* PortScanner.PortDiscovery; | 178 | const scanner = yield* PortScanner.PortDiscovery; |
| 222 | const result = yield* scanner.scan(); | 179 | const result = yield* scanner.scan([`http://localhost:${port}`]); |
| 223 | const found = result.find((server) => server.port === port); | 180 | const found = result.find((server) => server.port === port); |
| 224 | expect(found).toBeDefined(); | 181 | expect(found).toBeDefined(); |
| 225 | expect(found?.host).toBe("localhost"); | 182 | expect(found?.host).toBe("localhost"); |
| ... | @@ -231,7 +188,7 @@ effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (TCP probe fal | ... | @@ -231,7 +188,7 @@ effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (TCP probe fal |
| 231 | Effect.fn("PortScannerTest.scanExcludesNonHttpServer")(function* () { | 188 | Effect.fn("PortScannerTest.scanExcludesNonHttpServer")(function* () { |
| 232 | const { port } = yield* commonNonHttpServer; | 189 | const { port } = yield* commonNonHttpServer; |
| 233 | const scanner = yield* PortScanner.PortDiscovery; | 190 | const scanner = yield* PortScanner.PortDiscovery; |
| 234 | const result = yield* scanner.scan(); | 191 | const result = yield* scanner.scan([`http://localhost:${port}`]); |
| 235 | expect(result.some((server) => server.port === port)).toBe(false); | 192 | expect(result.some((server) => server.port === port)).toBe(false); |
| 236 | }), | 193 | }), |
| 237 | ); | 194 | ); |
| ... | @@ -242,10 +199,12 @@ effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (TCP probe fal | ... | @@ -242,10 +199,12 @@ effectIt.layer(layerTestPortDiscovery)("PortDiscovery integration (TCP probe fal |
| 242 | const { port } = yield* commonDevServer; | 199 | const { port } = yield* commonDevServer; |
| 243 | const received: number[] = []; | 200 | const received: number[] = []; |
| 244 | const scanner = yield* PortScanner.PortDiscovery; | 201 | const scanner = yield* PortScanner.PortDiscovery; |
| 245 | yield* scanner.subscribe({ configuredUrls: [], initialSnapshot: [] }, (servers) => | 202 | yield* scanner.subscribe( |
| 246 | Effect.sync(() => { | 203 | { configuredUrls: [`http://localhost:${port}`], initialSnapshot: [] }, |
| 247 | for (const server of servers) received.push(server.port); | 204 | (servers) => |
| 248 | }), | 205 | Effect.sync(() => { |
| | 206 | for (const server of servers) received.push(server.port); |
| | 207 | }), |
| 249 | ); | 208 | ); |
| 250 | yield* scanner.retain; | 209 | yield* scanner.retain; |
| 251 | expect(received).toContain(port); | 210 | expect(received).toContain(port); |
| ... | @@ -265,7 +224,7 @@ effectIt.effect("revalidates a successful HTML probe after its cache entry expir | ... | @@ -265,7 +224,7 @@ effectIt.effect("revalidates a successful HTML probe after its cache entry expir |
| 265 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 224 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 266 | | 225 | |
| 267 | return Effect.gen(function* () { | 226 | return Effect.gen(function* () { |
| 268 | const scanner = yield* PortScanner.PortDiscovery; | 227 | const scanner = yield* ownedScanner(); |
| 269 | expect(yield* scanner.scan()).toHaveLength(1); | 228 | expect(yield* scanner.scan()).toHaveLength(1); |
| 270 | expect(yield* scanner.scan()).toHaveLength(1); | 229 | expect(yield* scanner.scan()).toHaveLength(1); |
| 271 | expect(requests).toEqual([`http://localhost:${LSOF_TEST_PORT}/`]); | 230 | expect(requests).toEqual([`http://localhost:${LSOF_TEST_PORT}/`]); |
| ... | @@ -499,7 +458,7 @@ effectIt.effect("shares a configured root probe with discovered-root classificat | ... | @@ -499,7 +458,7 @@ effectIt.effect("shares a configured root probe with discovered-root classificat |
| 499 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 458 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 500 | | 459 | |
| 501 | return Effect.gen(function* () { | 460 | return Effect.gen(function* () { |
| 502 | const scanner = yield* PortScanner.PortDiscovery; | 461 | const scanner = yield* ownedScanner(); |
| 503 | expect(yield* scanner.scan([rootUrl])).toHaveLength(1); | 462 | expect(yield* scanner.scan([rootUrl])).toHaveLength(1); |
| 504 | expect(requests).toEqual([rootUrl]); | 463 | expect(requests).toEqual([rootUrl]); |
| 505 | | 464 | |
| ... | @@ -528,7 +487,7 @@ effectIt.effect("starts fresh cache entries after the probing batch completes", | ... | @@ -528,7 +487,7 @@ effectIt.effect("starts fresh cache entries after the probing batch completes", |
| 528 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 487 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 529 | | 488 | |
| 530 | yield* Effect.gen(function* () { | 489 | yield* Effect.gen(function* () { |
| 531 | const scanner = yield* PortScanner.PortDiscovery; | 490 | const scanner = yield* ownedScanner(); |
| 532 | expect(yield* scanner.scan()).toHaveLength(1); | 491 | expect(yield* scanner.scan()).toHaveLength(1); |
| 533 | expect(yield* scanner.scan()).toHaveLength(1); | 492 | expect(yield* scanner.scan()).toHaveLength(1); |
| 534 | expect(requests).toHaveLength(1); | 493 | expect(requests).toHaveLength(1); |
| ... | @@ -548,7 +507,7 @@ effectIt.effect("caches a failed web probe until its bounded cache entry expires | ... | @@ -548,7 +507,7 @@ effectIt.effect("caches a failed web probe until its bounded cache entry expires |
| 548 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 507 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 549 | | 508 | |
| 550 | return Effect.gen(function* () { | 509 | return Effect.gen(function* () { |
| 551 | const scanner = yield* PortScanner.PortDiscovery; | 510 | const scanner = yield* ownedScanner(); |
| 552 | expect(yield* scanner.scan()).toHaveLength(0); | 511 | expect(yield* scanner.scan()).toHaveLength(0); |
| 553 | expect(yield* scanner.scan()).toHaveLength(0); | 512 | expect(yield* scanner.scan()).toHaveLength(0); |
| 554 | expect(requests).toHaveLength(2); | 513 | expect(requests).toHaveLength(2); |
| ... | @@ -573,7 +532,7 @@ effectIt.effect("falls back to HTTPS and does not follow redirects while probing | ... | @@ -573,7 +532,7 @@ effectIt.effect("falls back to HTTPS and does not follow redirects while probing |
| 573 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 532 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 574 | | 533 | |
| 575 | return Effect.gen(function* () { | 534 | return Effect.gen(function* () { |
| 576 | const scanner = yield* PortScanner.PortDiscovery; | 535 | const scanner = yield* ownedScanner(); |
| 577 | const servers = yield* scanner.scan(); | 536 | const servers = yield* scanner.scan(); |
| 578 | expect(servers).toHaveLength(1); | 537 | expect(servers).toHaveLength(1); |
| 579 | expect(servers[0]?.url).toBe(`https://localhost:${LSOF_TEST_PORT}`); | 538 | expect(servers[0]?.url).toBe(`https://localhost:${LSOF_TEST_PORT}`); |
| ... | @@ -581,6 +540,37 @@ effectIt.effect("falls back to HTTPS and does not follow redirects while probing | ... | @@ -581,6 +540,37 @@ effectIt.effect("falls back to HTTPS and does not follow redirects while probing |
| 581 | }).pipe(Effect.provide(layer)); | 540 | }).pipe(Effect.provide(layer)); |
| 582 | }); | 541 | }); |
| 583 | | 542 | |
| | 543 | effectIt.effect("probes a port only while T3 terminals own every listener on it", () => { |
| | 544 | const owned = `p1234\ncnode\nn[::1]:${LSOF_TEST_PORT}\n`; |
| | 545 | const unowned = `p5678\ncrpc\nn127.0.0.1:${LSOF_TEST_PORT}\n`; |
| | 546 | let stdout = unowned; |
| | 547 | const requests: string[] = []; |
| | 548 | const fetchFn = ((input: Parameters<typeof globalThis.fetch>[0]) => { |
| | 549 | requests.push(String(input)); |
| | 550 | return Promise.resolve(new Response("app", { headers: { "content-type": "text/html" } })); |
| | 551 | }) as typeof globalThis.fetch; |
| | 552 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn, stdout: () => stdout }); |
| | 553 | |
| | 554 | return Effect.gen(function* () { |
| | 555 | const scanner = yield* ownedScanner(); |
| | 556 | expect(yield* scanner.scan()).toHaveLength(0); |
| | 557 | stdout = `${owned}${unowned}`; |
| | 558 | expect(yield* scanner.scan()).toHaveLength(0); |
| | 559 | expect(requests).toEqual([]); |
| | 560 | |
| | 561 | stdout = owned; |
| | 562 | expect(yield* scanner.scan()).toHaveLength(1); |
| | 563 | expect(requests).toEqual([`http://localhost:${LSOF_TEST_PORT}/`]); |
| | 564 | |
| | 565 | yield* scanner.unregisterTerminal({ |
| | 566 | threadId: "scanner-thread", |
| | 567 | terminalId: "scanner-terminal", |
| | 568 | }); |
| | 569 | expect(yield* scanner.scan()).toHaveLength(0); |
| | 570 | expect(requests).toHaveLength(1); |
| | 571 | }).pipe(Effect.provide(layer)); |
| | 572 | }); |
| | 573 | |
| 584 | effectIt.effect( | 574 | effectIt.effect( |
| 585 | "excludes HTTP errors, non-navigation responses, and successful non-documents", | 575 | "excludes HTTP errors, non-navigation responses, and successful non-documents", |
| 586 | () => { | 576 | () => { |
| ... | @@ -592,7 +582,7 @@ effectIt.effect( | ... | @@ -592,7 +582,7 @@ effectIt.effect( |
| 592 | const layer = layerLsofScanner({ pid: () => pid, fetch: fetchFn }); | 582 | const layer = layerLsofScanner({ pid: () => pid, fetch: fetchFn }); |
| 593 | | 583 | |
| 594 | return Effect.gen(function* () { | 584 | return Effect.gen(function* () { |
| 595 | const scanner = yield* PortScanner.PortDiscovery; | 585 | const scanner = yield* ownedScanner([1, 2, 3, 4, 5, 6, 7]); |
| 596 | expect(yield* scanner.scan()).toHaveLength(0); | 586 | expect(yield* scanner.scan()).toHaveLength(0); |
| 597 | | 587 | |
| 598 | pid += 1; | 588 | pid += 1; |
| ... | @@ -650,7 +640,7 @@ effectIt.effect("aborts HTTP and HTTPS probes when they time out", () => { | ... | @@ -650,7 +640,7 @@ effectIt.effect("aborts HTTP and HTTPS probes when they time out", () => { |
| 650 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); | 640 | const layer = layerLsofScanner({ pid: () => 1234, fetch: fetchFn }); |
| 651 | | 641 | |
| 652 | return Effect.gen(function* () { | 642 | return Effect.gen(function* () { |
| 653 | const scanner = yield* PortScanner.PortDiscovery; | 643 | const scanner = yield* ownedScanner(); |
| 654 | const scanFiber = yield* Effect.forkChild(scanner.scan()); | 644 | const scanFiber = yield* Effect.forkChild(scanner.scan()); |
| 655 | yield* TestClock.adjust(Duration.seconds(2)); | 645 | yield* TestClock.adjust(Duration.seconds(2)); |
| 656 | expect(yield* Fiber.join(scanFiber)).toHaveLength(0); | 646 | expect(yield* Fiber.join(scanFiber)).toHaveLength(0); |
| ... | @@ -739,11 +729,10 @@ effectIt.effect( | ... | @@ -739,11 +729,10 @@ effectIt.effect( |
| 739 | ); | 729 | ); |
| 740 | | 730 | |
| 741 | return Effect.gen(function* () { | 731 | return Effect.gen(function* () { |
| 742 | const scanner = yield* PortScanner.PortDiscovery; | 732 | const scanner = yield* ownedScanner([4242]); |
| 743 | const first = yield* scanner.scan(); | 733 | const first = yield* scanner.scan(); |
| | 734 | // Ports 22 and 3001 have no known owner, so they never receive probes. |
| 744 | expect(first.map(({ port, pid, processName }) => ({ port, pid, processName }))).toEqual([ | 735 | expect(first.map(({ port, pid, processName }) => ({ port, pid, processName }))).toEqual([ |
| 745 | { port: 22, pid: null, processName: null }, | | |
| 746 | { port: 3001, pid: null, processName: null }, | | |
| 747 | { port: 8765, pid: 4242, processName: "python3" }, | 736 | { port: 8765, pid: 4242, processName: "python3" }, |
| 748 | ]); | 737 | ]); |
| 749 | yield* scanner.scan(); | 738 | yield* scanner.scan(); |