Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…1044) The test failed on the first duplicate among 2000 generateJobArrayID calls. The suffix is 32 bits from crypto/rand, so 2000 draws collide with probability n^2/2^33 = 4.7e-4: about one run in 2000, 6 of 20000 measured. A clock-derived suffix, the #710 regression the test exists to catch, duplicates hundreds of times in the loop (1362 of 2000 against the old UnixNano()%0xFFFFFF code on darwin). Entropy duplicates more than once with probability about 1.1e-7. The test now fails on more than one duplicate, and TestDuplicateToleranceStillCatchesAClock checks that the tolerance still rejects clock-like sources. The id is unchanged. A production collision needs the same name on the same day (P about k^2/2^33 for k such launches).
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.
Fixes #1044
Verified
The test called
generateJobArrayID2000 times and failed on the first duplicate. The suffix is 32 bits fromcrypto/rand. The birthday bound for 2000 draws is n²/2^33 ≈ 4.7 × 10⁻⁴. On main,go test ./cmd -run '^TestJobArrayIDSuffixIsNotTheClock$' -count=20000failed 6 times out of 20000. The duplicates were far apart in the sequence (for example calls 724 and 1066), so they were real random collisions, not a clock.Fix: the test, not the id
The test exists to catch #710: a suffix derived from the clock. That source duplicates massively. Against the old
UnixNano()%0xFFFFFFcode on darwin, the loop now reports 1362 duplicates in 2000 calls. Entropy produces two or more duplicates with probability about λ²/2 ≈ 1.1 × 10⁻⁷. So the test now fails on more than one duplicate.duplicateIDs(gen, n)collects every repeat, and the failure message reports the count and the first five.TestDuplicateToleranceStillCatchesAClockchecks that deterministic clock-like sources still exceed the tolerance. They repeat every 2, 4 and 100 calls (the last gives 20 duplicates).-count=20000passes.Watched failing, with reverts that compile:
randomIDSuffixreverted to the generateJobArrayID's "random suffix" is a timestamp, so two job arrays can share an id — and #691's gate cannot catch it on a microsecond-resolution clock #710 clock suffix:TestJobArrayIDSuffixIsNotTheClockfails with "1362 duplicate ids in 2000 calls".TestDuplicateToleranceStillCatchesAClockfails.Why not widen the suffix
A production collision needs all three parts of the id to match: the same
--job-array-name, the sameYYYYMMDD, and the same 32-bit suffix. For k launches sharing a name on one day, P ≈ k²/2^33. That is about 1.2 × 10⁻⁶ at 100 launches and 1.2 × 10⁻⁴ at 1000. The date already bounds the window to roughly EC2's ClientToken idempotency window. Widening would change the id's length and format, which appears in tags, DNS group registration andspawn arrayoutput, for no measurable gain.Checks
make check(credentials stripped): the only failure is the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nested: 9 modules clean.Caveat
The comment on the original test claims the tight loop catches a clock suffix "on any platform". On Linux's nanosecond clock, 2000 calls take well under the ~16.8 ms wrap, so the old suffix might not repeat at all within the loop. This PR does not change that, and it was already true.