Repository navigation
fix: make testMixedModeMayTargetAnyPeer deterministic via an internal randomInt seam (#817) - #1048
Open
IG-ABHINAV wants to merge 1 commit into
Open
IG-ABHINAV wants to merge 1 commit into
IG-ABHINAV wants to merge 1 commit into
Conversation
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
Makes
testMixedModeMayTargetAnyPeerdeterministic by adding an internal test seam toRegionContextFactory::resolveTarget()— an optional?Closure(int, int): int $randomInt = nullparameter that defaults to the existingrandom_int(...)pick — and having the test drive that seam with a sequence that visits every candidate.Why
Issue #817: the test looped 20 random draws and asserted all three peers (stores 3, 4, 5) appeared. With three candidates the chance at least one peer is missed is ~0.09% per run, and it has already failed CI on PR #807 (
Failed asserting that an array contains 4), costing a rerun on an unrelated PR and eroding trust in the suite. Randomized coverage should not be a pass/fail condition.How
src/Client/Region/RegionContextFactory.phpresolveTarget()gains a trailing?Closure $randomInt = nullparameter, documented in the phpdoc as an internal/test-only seam (issue testMixedModeMayTargetAnyPeer is flaky: 20 random draws must hit all three peers #817).$randomInt(0, count($candidates) - 1)when the seam is supplied, otherwise the unchangedrandom_int(0, count($candidates) - 1). All production call sites (positional, up to$storeAvailable) are unaffected and keep the historical random behaviour by default.tests/Unit/Region/ReplicaReadTargetResolutionTest.phptestMixedModeMayTargetAnyPeernow injects a counter-driven closure cycling through every candidate index, so each of stores 3, 4, 5 is hit on a fixed schedule. The per-draw assertion that every pick is in{3, 4, 5}was added; the threeassertContainschecks are now guaranteed rather than probabilistic.testMixedModeUsesRandomPickWhenNoSeamIsSuppliedlocks in the default path: with no seam, 64 unseeded draws still reach all three peers (miss probability ~1.6e-11 — orders of magnitude below the flake being fixed), proving the default was not pinned to one index.Verification
Duplicate check:
git log origin/master --oneline -20 | grep -F '#817'→ no hits.Judgment calls
phpcsreports onlyGeneric.Files.LineEndingson both files locally:core.autocrlf=truemakes the worktree CRLF while the index/CI checkout is LF (baseline fails identically); committed blobs arei/lf.