test(apiTests): isolate per-process loopback address to prevent port collisions - #1177
Merged
Conversation
Each mocha run now acquires a unique 127.0.0.x address from the @harperfast/integration-testing loopback pool before starting the in-process Harper server, so concurrent agent runs bind to different addresses and never collide on ports 9925/9926/1883/8883. - setupTestApp.mjs: call getNextAvailableLoopbackAddress() on first server start; update all setProperty() port bindings (HTTP, MQTT, MQTT-TLS, operations API) to use the acquired address; export baseUrl/wsBaseUrl/operationsUrl/mqttUrl/mqttsUrl/testHost live bindings so test files see the address without any re-import; release address on beforeExit; set HARPER_TEST_HOST env var for CJS callers - utility.js: read HARPER_TEST_HOST / HARPER_TEST_OPS_PORT env vars so callOperation() reaches the correct operations API address - All *-test.mjs files: import the relevant URL variables and replace every hardcoded http://localhost:9926, ws://localhost:9926, http://localhost:9925, mqtt://localhost:1883, mqtts://localhost:8883 reference; also bind the ephemeral mTLS test listeners (8884/8885) to testHost so they follow the loopback assignment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add missing baseUrl import to mqtt-test.mjs, remove spurious setupTestApp import from ws-json-work.mjs, apply prettier reformats. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ches resources.js runs inside the Harper instance and fetches back from itself via HTTP. When the test server is bound to a loopback address other than localhost, the hardcoded http://localhost:9926 fetch fails. Read HARPER_TEST_HOST (set by setupTestApp) to build the correct origin. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
kriszyp
marked this pull request as ready for review
June 9, 2026 02:09
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
|
Reviewed; no blockers found. |
ldt1996
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setupTestApp.mjsacquires a unique127.0.0.xloopback address from@harperfast/integration-testing's pool and binds all server ports (HTTP 9926, ops 9925, MQTT 1883/8883) to it*-test.mjsfiles now import dynamic URL variables (baseUrl,wsBaseUrl,operationsUrl,mqttUrl,mqttsUrl,testHost) instead of hardcodinglocalhoststringsutility.js(CJS) readsHARPER_TEST_HOST/HARPER_TEST_OPS_PORTenv vars set bysetupTestApp.mjstestApp/resources.jsreadsHARPER_TEST_HOSTfor theCacheOfHttpsource's self-fetchesPurpose
test:unit:apitestshard-codedlocalhost:9926/9925/1883/8883— running two agents simultaneously caused server startup conflicts. This gives each process its own isolated loopback address, matching howtest:integration:*tests work.Areas for attention
serverStartedguard: address acquisition is gated on!serverStarted, so re-entrantsetupTestApp()calls (for test re-initialisation) don't acquire a second address. ThesetPropertycalls run unconditionally, which is correct — they re-set the same host on reuse.beforeExitvsprocess.exit(): mocha callsprocess.exit()explicitly, sobeforeExitmay not fire. The integration-testing pool uses PID liveness detection so leaks self-heal; this is a known limitation, not a defect.mqtt-test.mjsbinds short-lived TLS listeners; changed tolisten(port, testHost, callback).CacheOfHttpsource inresources.jsstill fetchedhttp://localhost:9926. Fixed in commit9185ef0b1usingprocess.env.HARPER_TEST_HOST.Invalid auth method selected).Generated by Claude Sonnet 4.6