Skip to content

acc: add a fault mode that reruns each test with one request failed - #8133

Open
denik wants to merge 9 commits into
mainfrom
denik/acc-fault-sweep
Open

denik wants to merge 9 commits into
mainfrom
denik/acc-fault-sweep

Conversation

@denik

@denik denik commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Changes

A fault mode for acceptance tests that checks that the CLI and the tests survive a single backend error. With go test ./acceptance -faultcount N, each test that passes runs again as subtests fault=1 to fault=N, each with one request failed, and must produce the same outputs. -faultcount all runs every request with every fault kind.

  • The fault kinds: 429, 500, 502, 503, 504, a 504 after the testserver applied the request, a connection reset before or after the request is applied, and a truncated response body.
  • The CLI should retry the failed request. Retry warnings are suppressed by SuppressLines.warn_retry, and the failed attempt is dropped from out.requests.txt, as the cloud proxy already does.
  • Faults are drawn from the requests of the test's clean run. Each request is named by a stable key, its method and path with the test's replacements applied, plus its occurrence, e.g. GET /api/2.0/workspace/get-status #3. The pairs of request and kind are ordered by a hash of the seed, the test name and the pair. So fault=k is the same fault on every run, whatever N is and whatever order the test made its requests in.
  • -faultseed defaults to the current git commit. Each fault run logs its fault and the exact command that reruns it.
  • Opt-outs in test.toml, inherited like other settings:
    • FaultInjection = false for a test that pins the exact request sequence or injects faults itself;
    • FaultSkip = ["GET /api/..."] for requests that must not be failed.
    • Tests that set SuppressLines.warn_retry = "" are left out automatically.
  • Fault mode keeps the shared testserver, so a test's clean run is its normal run. The shared server tells tests apart by their token, as it does for fake workspaces and kill rules; requests without a token, such as host metadata or OAuth endpoints, are not failed there. Tests with a testserver of their own ([[Server]] stubs, RecordRequests) can have any request failed.
  • Test helpers that are not the CLI under test (replay_tfstate.py, browser.py, the selftest curls) send X-Databricks-Test-No-Fault, and their requests are never failed.

Why

Backend errors on real workspaces are the main source of flaky cloud tests, and of user-visible failures that a retry would have hidden. This finds requests the CLI does not retry without waiting for them to show up on cloud. A sweep over all tests found unretried 5xx and truncated-body errors on common calls, and non-idempotent retries in deployment history and in resource creates; #8253 addresses the GET 500 part.

CI runs it in a new test-faults job (./task test-faults): on each push to main, one fault for every test; on pull requests, ten faults for each test the PR changes. The seed is the head commit, so go test ./acceptance -run ... -faultcount N on that commit reproduces a failure. The job is not in test-result's needs, so it does not block merging while the CLI still fails on some faults.

Tests

  • Unit tests for the testserver faults, request keys, the draw (distinct, a prefix for a smaller count, independent of request order, skip patterns), the opt-outs, and the recorder dropping the failed attempt.
  • -faultcount 3 on bundle/resources/jobs/update (4 variants): 11 fault runs pass. 1 fails on a 502 to GET bundle/enrollments:check, a real gap, and its printed rerun command reproduces it alone.
  • The full acceptance suite passes without -faultcount.
  • -faultcount all on three tests on the shared testserver (cmd/workspace/import-export, create-scope, clusters-list): 1737 fault runs. 429, 503 and a reset before the request are retried every time. 500, 502, 504, 504 after the request and truncated bodies fail every time. A reset after the request fails 35 of 193 runs. No request without a token was failed.
  • DATABRICKS_TEST_SELECT_CHANGED=50 ./task test-faults (as on PRs) on this branch selects the two changed selftests; see the example in the comments.

This pull request and its description were written by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 333332a

Run: 46696823164

Env ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 77 8 1:32
✅​ aws-windows-latest-4core-16gb 77 8 3:26
✅​ azure linux-2core-8gb 77 8 1:47
✅​ azure-windows-latest-4core-16gb 77 8 3:12
✅​ gcp linux-2core-8gb 77 8 1:48
✅​ gcp-windows-latest-4core-16gb 77 8 3:06
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:25 aws-windows-latest-4core-16gb TestAccept
3:10 azure-windows-latest-4core-16gb TestAccept
3:04 gcp-windows-latest-4core-16gb TestAccept

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: 333332a19 | Workflow run

Selected 2 changed tests (limit=20, 0 not selected)

5 tests: regression=0 unreleased=0 coverage=5 failing=0
test branch main (e5d6079) latest (v1.28.0)
TestAccept/selftest/diff ✅ ✅ ✅
TestAccept/selftest/server/VARIABLE_A=one/VARIABLE_B=HELLO ✅ ✅ ✅
TestAccept/selftest/server/VARIABLE_A=one/VARIABLE_B=WORLD ✅ ✅ ✅
TestAccept/selftest/server/VARIABLE_A=two/VARIABLE_B=HELLO ✅ ✅ ✅
TestAccept/selftest/server/VARIABLE_A=two/VARIABLE_B=WORLD ✅ ✅ ✅

@denik denik changed the title acc: add a fault sweep that fails one request per test to check CLI retries acc: add fault sweeps that fail one request per test to check CLI retries Nov 29, 2026
stevenayers pushed a commit to stevenayers/cli that referenced this pull request Nov 30, 2026
…icks#8172)

## Changes
The acceptance test proxy (`libs/testproxy`) no longer retries. It
forwards what upstream answered, failures included:
- 429/503/504 are passed to the client after one attempt.
- If the upstream connection fails before a response, the proxy resets
the client's connection.
- If the upstream response body is cut short, the client's body is cut
short too.

The request recorder treats a response it never got (status 0) as
transient, so the CLI's retry is dropped from `out.requests.txt` as it
already is for 5xx.

## Why
The proxy forwards through an SDK `ApiClient`, which retries 429, 503,
some 504s and connection errors itself. Those failures never reached the
CLI under test, so a `Proxy = true` test or a cloud recording run could
not show whether the CLI handles them. This came up in
[databricks#8133](databricks#8133), where an injected
fault hidden by the proxy would count as a pass.

The SDK retries some connection errors by message no matter what
`ErrorRetriable` returns, so the proxy's transport replaces their
message. Go's `net/http` still repeats an idempotent request that fails
on a reused connection, as it does without the proxy.

## Tests
New unit tests in `libs/testproxy`: retriable statuses, a connection
reset and a truncated body each reach the client after exactly one
upstream call. `acceptance/selftest` passes locally. Not run on cloud.

🤖 AI agent (opus5.5, isaac_claude)

This pull request and its description were written by Isaac.

---------

Co-authored-by: Isaac <no-reply@databricks.com>
idelafuente-oc pushed a commit to idelafuente-oc/cli that referenced this pull request Nov 30, 2026
…ricks#8193)

## Changes
`acceptance/bin/replay_tfstate.py` now pushes the remote copy of the
replayed terraform state with its own `api()` helper (`POST
/api/2.0/workspace/mkdirs` and `POST /api/2.0/workspace/import`),
instead of running `$CLI workspace mkdirs` and `$CLI workspace import`.
It sends the same two requests, so no goldens change.

## Why
The script sets up state for a test; it isn't the CLI under test. All of
its other calls already go to the API directly, and these two were the
only ones that went through the CLI. This is a prep step for
[databricks#8133](databricks#8133), which injects
backend errors into the CLI's requests. Setup that the CLI performs
would get those faults too, and the script does not retry.

## Tests
All 51 acceptance test dirs that use the script pass locally
(`bundle/migrate`, `bundle/invariant/{migrate,auto-migrate}`,
`bundle/config-remote-sync/terraform_state`,
`bundle/state/state_present`), with unchanged goldens.

This pull request and its description were written by Isaac.

---------

Co-authored-by: Isaac <no-reply@databricks.com>
denik and others added 6 commits December 1, 2026 11:58
…ries

Co-authored-by: Isaac <no-reply@databricks.com>
Helpers that set up state or play the user's browser (replay_tfstate.py,
browser.py, the selftest curls) send X-Databricks-Test-No-Fault. The
testserver neither counts nor fails such requests, and -faultlog reports
how many each test sent. replay_tfstate.py now pushes the remote state with
its own API calls instead of the CLI, so its setup is never faulted.

Co-authored-by: Isaac <no-reply@databricks.com>
A fault now targets a request key (method and path with the test's
replacements applied, plus an occurrence) instead of a position in the
request sequence, which shifts when the CLI calls in parallel. Plan keys may
leave out EnvMatrix segments to cover all matching variants. fault_sweep.py
gains --mode exhaustive (every request x every kind), --plan FILE (lists of
faults per test), and writes failures.plan.json. Tests that assert their
own retry warnings are left out by default.

Co-authored-by: Isaac <no-reply@databricks.com>
Each test that passes reruns as subtests fault=1..N, one request failed
in each. The faults are drawn from the clean run's requests by a hash
of the seed, the test name and the request key, so fault=k is the same
fault on every run whatever N is. -faultcount and -faultseed replace
-faultplan, -faultlog and tools/fault_sweep.py. Tests opt out with
FaultInjection = false or skip requests with FaultSkip.

Co-authored-by: Isaac <no-reply@databricks.com>
@denik
denik force-pushed the denik/acc-fault-sweep branch from c11ec08 to 3c3e8c4 Compare December 1, 2026 12:30
@denik denik changed the title acc: add fault sweeps that fail one request per test to check CLI retries acc: add a fault mode that reruns each test with one request failed Dec 1, 2026
@github-actions github-actions Bot added the test-only-fix PRs that update failing of flaky tests without changing CLI code. label Dec 1, 2026
Add the test-faults job and the task behind it: one fault per test on
each push to main, ten per changed test on pull requests, seeded by the
head commit. The job is not in test-result's needs, so it does not block
merging while the CLI still fails on some faults.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: denis.bilenko <denis.bilenko@databricks.com>
@github-actions github-actions Bot removed the test-only-fix PRs that update failing of flaky tests without changing CLI code. label Dec 1, 2026
@denik
denik marked this pull request as ready for review December 1, 2026 14:29
@denik
denik requested a review from a team as a code owner December 1, 2026 14:29

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at 952fa4b. Each finding was verified against the code.

Not ready yet: 1 blocking issue(s), tagged [blocking].

This PR adds a -faultcount mode to the acceptance harness. Each passing test reruns with one testserver request failed (5xx, reset or truncated body), and a non-blocking test-faults CI job runs it. The mechanism holds together. One new unit test asserts a Unix-only error string and will fail on the Windows task test cells. A few smaller issues remain: a stray -faultseed is silently ignored, the printed rerun command is less reproducible than the docs claim, and fault reruns go parallel in the in-process and benchmark paths.

Questions

  1. The test-faults job runs on every PR and every push to main, but the description already lists failures it hits, including this PR's own selftests and bundle/resources/jobs/update. No test.toml in the change sets FaultInjection = false or FaultSkip for the known gaps, so the check is expected to be red from the start, and a new gap won't stand out. Should it run on the existing nightly schedule trigger or locally until the known cases are opted out? The alternative is to add those opt-outs in this PR. (non-blocking)

Comment thread libs/testserver/request_fault_test.go Outdated
if kind == testserver.FaultTruncatedLate {
assert.ErrorContains(t, err, wantErr)
} else {
assert.Regexp(t, wantErr+"|EOF", err.Error())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] On Windows, an RST from SetLinger(0) surfaces as wsarecv: An existing connection was forcibly closed by the remote host.. That matches neither connection reset by peer nor EOF, so the reset and reset-after subtests fail in the Windows task test cells (AGENTS.md: tests also run on Windows). Can you check errors.Is(err, syscall.ECONNRESET) instead? Go maps WSAECONNRESET to it. Keep io.EOF as the timing fallback, or just require a non-nil error.

// ParseFaultFlags parses -faultcount and -faultseed. It must run before any test starts.
func ParseFaultFlags() error {
switch FaultCountFlag {
case "", "0":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] When -faultcount is empty or 0, ParseFaultFlags returns before it looks at FaultSeedFlag. So go test ./acceptance -run ... -faultseed abc123 with -faultcount edited out of a copied rerun command runs a normal pass and reports no error. AGENTS.md asks for an error when a flag can't be honored. Can this return -faultseed requires -faultcount when FaultSeedFlag != "" and fault mode is off?

}

// FaultReproFlags returns the flags that rerun fault=k with the same fault.
func FaultReproFlags(k int) string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] FaultReproFlags reproduces a fault by its index k in the hash-sorted list of the clean run's requests. If the local clean run makes one more or one fewer request than CI, every later index moves, and the printed command fails a different request. A timing-dependent poll (GET .../runs/get #5) is enough to cause that. On pull requests, CI also builds the merge commit (actions/checkout) while the seed is the head SHA (push.yml), so a local run on the head commit can draw from a different list once main has moved. Could the rerun command name the fault directly, for example a -fault 'GET /api/... #3 503' flag, instead of an index?

for i, fault := range faults {
k := i + 1
t.Run(fmt.Sprintf("fault=%d", k), func(t *testing.T) {
if !InprocessMode {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] This checks the global InprocessMode, but testAccept decides parallelism from its inprocessMode argument and from benchmarkMode. TestInprocessMode calls testAccept(t, true, ...) while the flag stays false, so go test ./acceptance -faultcount 3 without -run '^TestAccept$' runs the fault=k reruns of selftest/basic in parallel through the single in-process cmd server. Benchmark dirs that are deliberately kept serial also get parallel fault reruns. Can runTest take runParallel as a parameter from testAccept instead?

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: denis.bilenko <denis.bilenko@databricks.com>
@denik

denik commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Example: what the test-faults job found on this PR (run, seed 952fa4b6d543).

The PR changes two selftests, so the job ran them with 10 faults per variant. selftest/diff makes only helper requests, which are marked no-fault, so it got none. selftest/server got 40 fault runs over its 4 variants: 25 passed and 15 failed. Every failure is a backend error that databricks workspace get-status does not survive:

Request Fault Runs Result What the CLI printed instead of Error: Path (/a/b/c) doesn't exist.
GET /api/2.0/workspace/get-status 500 4 fail Error: Injected fault: internal error. (#8253 retries this one)
GET /api/2.0/workspace/get-status 502 2 fail Error: upstream connect error or disconnect/reset before headers. reset reason: connection termination
GET /api/2.0/workspace/get-status 504, 504 after the request was applied 4 fail Error: upstream request timeout
GET /api/2.0/workspace/get-status truncated body 2 fail Error: response body: unexpected EOF
GET /.well-known/databricks-config truncated body 1 fail the command still works, but prints an extra Warn: [hostmetadata] failed to fetch host metadata for [DATABRICKS_URL], will skip for 1m0s
both requests 429, 503, connection reset before or after the request 16 pass retried
GET /.well-known/databricks-config 500, 502, 504, 504 after 8 pass host metadata is optional, so the CLI carries on without printing anything

Each fault run logs the command that reruns it, for example:

Failing GET /api/2.0/workspace/get-status #1 with 504. Rerun: go test ./acceptance -run '^TestAccept$/^selftest$/^server$/^VARIABLE_A=two$/^VARIABLE_B=HELLO$/^fault=6$' -faultcount 6 -faultseed 952fa4b6d543

An earlier sweep over all tests, with 2 faults per test, found the same classes of failure in many more places: unretried 502, 504 and truncated bodies on common reads such as scim/v2/Me, get-status, workspace/export and enrollments:check; and retries of requests the server had already applied, in deployment-history version create, operation PATCH and resource creates.

This comment was written by Isaac.

// NoFaultHeader marks a request that a test helper sends, such as replay_tfstate.py setting up
// remote state, rather than the CLI under test. Such requests are not counted or failed: the
// point is to check that the CLI retries, and the helpers do not.
const NoFaultHeader = "X-Databricks-Test-No-Fault"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The well-known config curl in setup_custom_host and its copy in strict_profile_match's script.prepare don't send this header, so a fault there breaks setup, not the CLI. Should both send it?

Key request faults on the test's token, as the shared testserver already
does for fake workspaces, kill rules and fault rules, so fault mode no
longer gives each test a testserver of its own and its clean run is the
normal run. Requests without a token, such as host metadata, belong to no
test on the shared server and are not failed; tests with a testserver of
their own still cover them.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: denis.bilenko <denis.bilenko@databricks.com>

@Sankalp-Mittal Sankalp-Mittal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Generated] Review by review-factory (Claude Opus 5.5 + Claude Sonnet 5.5 + Claude Opus 5.5, cross-verified). Only points the reviewers agreed on are posted.

Design, could be simpler: runTest, PrepareServerAndClient and runTestOnce pass the planned fault and its RequestFaults scope to each other through two package-level sync.Maps keyed by *testing.T. If the fault were passed into PrepareServerAndClient/startLocalServer and the scope returned from runTestOnce, both maps would go, along with PlanFault, PlannedFault, faultScope and FiredFault. DrawFaults would then take the keys.

return nil, fmt.Errorf("%w: FaultInjection = false", ErrNoFaults)
}
// Such a test asserts the retries it causes itself, so an extra retry changes its output.
if pattern, set := config.SuppressLines["warn_retry"]; set && pattern == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Generated] Tests using kill_after.py, fault.py or /__testserver still get fault runs; in selftest/kill_caller/offset a retried fault shifts the kill window. Could these tests opt out, or be excluded automatically like warn_retry = ""?

switch kind {
case FaultGatewayTimeoutLate:
s.writeResponse(w, request, faultStatusResponses[FaultGatewayTimeout])
case FaultReset, FaultResetLate:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI Generated] reset and eof-after reimplement testproxy's resetConnection, truncateResponse and hijack (libs/testproxy/server.go:294-323), and testproxy already imports testserver. Could testserver export one shared helper that both use?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants