Repository navigation
fix(cli): always build the fault controller, and seed it from config - #585
Merged
Merged
Conversation
substrate server built a FaultController only when the config file had
fault.enabled or at least one rule. On a default server all three
/v1/fault/rules endpoints therefore answered
501 fault injection not enabled on this server
so a harness could not arm a rule at all — which is the remedy the docs point
at. The controller is now always constructed; a disabled one makes InjectFault a
no-op, so behavior is unchanged for a run that never arms a rule. A Server
constructed in-process with no controller still answers 501, which
TestFaultControl_NilController_Returns501 asserts.
The seed came from time.Now().UnixNano(), so a probabilistic rule loaded from a
config file produced a different run every time. fault.seed now supplies it,
defaulting to 0 — deterministic, which is what this emulator is for; the
wall-clock seed was the anomaly.
Construction moved into newFaultController so a test can assert both halves
without starting a server. Both mutants — restoring the conditional construction,
and restoring the wall-clock seed — are caught.
Also fixes the testing guide's fault example, which called
substrate.WithFaultController(fc): that symbol exists nowhere in the repo, so the
example never compiled. The option is substrate.ServerOptions{Fault: fc}. The
guide gains a section on arming rules over the wire and on fault.seed, replacing
a TODO that pointed at a closed issue and at that same non-existent symbol.
6 tasks done
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.
Two gaps that made the fault tier unreachable from a config file
A default server answered 501.
substrate serverbuilt aFaultControlleronly when the config file had
fault.enabledor at least one rule(
main.go:153-156). Without one, all three/v1/fault/rulesendpoints returned501 fault injection not enabled on this server, so a harness could not arm a ruleon a default server at all — which is precisely the remedy
docs/testing-guide.mdpoints a reader at. This is not hypothetical: it silently swallowed the first probe
of the #540 investigation.
Its seed was the wall clock. When the controller was built, it came up with
time.Now().UnixNano(), andFaultCfghad no seed field, so a config file couldnot pin it. A probabilistic rule from a config file therefore produced a different
run every time — the one property this emulator exists to avoid.
StartTestServeralready did the right thing in-process (NewFaultController(..., 1)); only the CLI path was affected.The fix
The controller is always constructed. A disabled one makes
InjectFaultano-op, so behavior is unchanged for every run that never arms a rule; only a
Serverconstructed in-process with no controller still answers 501, whichTestFaultControl_NilController_Returns501asserts and which still passes.fault.seed(int64,mapstructure:"seed") supplies the seed, defaulting to0— deterministic, which is what Substrate is for. Documented inconfigs/substrate-local.yamland the testing guide.Construction moved into a
newFaultControllerfunction so a test can assert bothhalves without starting a server. That seam exists because it was needed: the first
run of the mutation pass had the mutant restoring conditional construction
SURVIVE, since every existing test built its server in-process and none
exercised the CLI's construction path at all.
Also: the testing guide's fault example did not compile
It called
substrate.WithFaultController(fc)— a symbol that exists nowhere in therepo. The option is
substrate.ServerOptions{Fault: fc}. Found by grep whilescoping this.
The
<!-- TODO(#178): document server.WithFaultController option once stabilised -->beneath it is replaced with the documentation it was deferring: #178 is closed,and the symbol it names never existed. In its place, a short section on arming rules
over the wire and on
fault.seed.Tests
cmd/substrate/main_test.go—TestNewFaultController_AlwaysBuiltAndSeeded: adefault config yields a non-nil controller (with preconditions asserting the
default config really does not enable faults, so the test cannot pass vacuously);
it injects nothing until armed; arming makes a rule fire; and the configured seed
reaches the controller — the same seed traces identically over 24 requests, a
different seed does not, and the trace contains both outcomes so "reproducible"
is not trivially true.
emulator/fault_wiring_test.go—fault.seedround-trips throughToFaultConfigwith the default asserted as0, and a disabled controlleraccepts rules over the wire and then fires them with
firedincremented.Mutation tested, 2 mutants, both CAUGHT after the seam was added:
restoring the conditional construction, and restoring
time.Now().UnixNano().Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...(0issues),
make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all clean.End to end against a default
substrate serverwith nofault:block: