Repository navigation
LTS: flush and finish open runs as interrupted on SIGTERM - #65
Merged
shubhamkd merged 4 commits intoOct 26, 2026
Merged
Conversation
adityasonani-bs
marked this pull request as ready for review
October 22, 2026 12:31
The LT SIGTERM flush has to finish inside the plugin's stop deadline, and makeRequest had no request-level bound: @cypress/request's `timeout` covers only the connect and the gaps between bytes, so a response that trickles in, or a call queued behind the 2-socket agent, could hold a stage until the 45s socket timeout. makeRequest now honours config.timeout as a wall-clock bound (abort and reject), and the queue drain passes one through. Callers that set no timeout send exactly the config they sent before.
A test the runner cuts mid-run has to land in TestHub as one `interrupted` row, the same row its TestRunStarted opened. The synthetic teardown finish lacks file_name, location, vc_filepath, integrations and product_map, so it re-hashes into a second Tests-tab row. On LT runs the plugin now keeps each run's TestRunStarted payload and builds the interrupted finish from it: the same identity fields, the lowercase 'interrupted' literal TestHub maps by exact match, a time-to-cut duration_in_ms, and the LCNC steps completed before the cut, capped as a prefix so TestHub's 131072-char meta limit never drops them all. The finishes go in their own batch request, and the build stop takes a per-request timeout. Non-LT runs keep no copy and send what they sent.
When the load-testing runner cuts a Nightwatch / LCNC run (a stop, a timeout, or its own end-of-duration or rampdown cut) the plugin died on the group TERM: the cut test stayed pending, its completed LCNC steps were lost, and so was the last ~2s batch of finished results. For an LT session with a TestHub build and the runner's PID-file env (BROWSERSTACK_LTS_SDK_PID_FILE), and without BrowserStack Local, before() now writes the PID file (bare PID, 0644, atomic, removed on exit) and installs one SIGTERM handler. On the signal it ignores new test events, finishes every open run as interrupted and marks it finished, waits for in-flight events, drains the queue, sends the interrupted finishes in their own request, stops the build, and exits 143. Each request has its own timeout and the whole flush is bounded by the stop deadline; when it runs out the build stop, then the interrupted POST, are the ones dropped. Whichever of after() and the handler starts first owns the teardown. EPIPE on stdout or stderr is ignored, and the handler never calls the browser. Without all of those conditions nothing is installed, so hand-run Nightwatch, older images and non-LT users run exactly as before.
adityasonani-bs
force-pushed
the
lts-sigterm-interrupted
branch
from
October 23, 2026 09:51
b5259c7 to
c3e2711
Compare
makeRequest's whole-call timer is now keyed on a new `totalTimeout` option that only the LTS stop path sets (the queue drain, the build-stop PUT and the interrupted POST). `timeout` keeps @cypress/request's connect/idle meaning, so test orchestration's `timeout: 30000` is no longer a 30 s abort of a live response for non-LT users. Regression test: "does not abort a live trickling response when only `timeout` is set" fails on the previous head and passes here.
MihirR-BS
approved these changes
Oct 23, 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.
What
Adds an LT-only SIGTERM path for runs on BrowserStack's Load Testing Service (LTS). When the load-testing runner stops a run partway (a user stop, a timeout, or the runner's own end-of-duration cut), the plugin now finishes the tests that were still open as
interrupted, with the steps they had completed, instead of dying on the signal and losing them.The path is installed in
before, afterlaunchTestSession, only when all of these hold:helper.isLoadTestingSession()is true;BROWSERSTACK_TESTHUB_UUIDandBROWSERSTACK_TESTHUB_JWTare set (a TestHub build exists);BROWSERSTACK_LTS_SDK_PID_FILEis set (only the LTS runner exports it);Without all four, nothing is installed and the plugin behaves exactly as today, so non-LT users see no change.
Once installed, the plugin writes the PID file (bare PID, mode 0644, via a tmp file and an atomic rename), registers one SIGTERM handler, and removes the PID file on exit. On SIGTERM the handler (idempotent; a second signal is ignored):
TestRunStarted/TestRunFinishedevents;TestRunFinishedwith resultinterruptedfor each open run, from that run's ownTestRunStartedpayload (same identity fields, so the sametest_hashand the same Tests-tab row), withfinished_at= the cut time,duration_in_ms= the time to the cut and, for LCNC runs, a snapshot of the completedglobal.__bstack_stepsinmeta.steps; each run is marked finished first, so a late real finish or the teardown sweep cannot write over it;Bounds: every request on this path has its own wall-clock timeout (2000 ms, through a new
totalTimeoutoption ofmakeRequestthat bounds the whole call; only this path sets it, sotimeoutkeeps its connect/idle meaning for every other caller), and the whole flush has a deadline (8000 ms). If the deadline runs out, unsent work is dropped from the end: the build stop first, then the interrupted POST. Each leaves today's outcome (an open build, a test left pending).meta.stepsis capped at 126976 characters, 4096 under TestHub's 131072-charactermetalimit; if the steps do not fit, the earliest completed steps that fit are kept.after()and the handler share a teardown-owner flag: whichever starts first owns the sweep, the queue drain and the build stop. The path never callsbrowser.*and ignores EPIPE on stdout and stderr.No version bump in this PR; the release is left to the maintainers.
Diff: 8 files, +1125 -10, of which 910 lines are new tests (
test/src/test-observability/ltsStopPath.js719,test/src/utils/ltsRequestTimeout.js191).Why
On the Load Testing Service a Nightwatch run can be cut while a test is still running. The plugin and Nightwatch handle no signals, so the cut test stayed pending, the steps an LCNC test had completed were lost, and so were the results in the plugin's last ~2 s batch. With this change the cut test is reported
interrupted(an existing TestHub result, counted under Other; no new status), its completed steps are attached, and the last batch is delivered.Testing
npm test(mocha --recursive --timeout 10000, withBROWSERSTACK_USERNAMEandBROWSERSTACK_ACCESS_KEYunset): 159 passing, 0 failing (110 existing plus 49 new), on Node 18.18.0.npm run eslint: clean.