You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regression: assertion left == right failed but it depends on library-unstable details #128899
Other initial hypothesis is that the library is doing panic recovery. Perhaps some other library in its dep tree is sorting but then panic recovery occurs? survemobility/gaffer@f238bae
coding-problems-practice has a now-failing-tests solution, but it actually is still correct according to the original problem.
the tests seem to rely on sort_unstable_by having sorted things a certain way,
sort_unstable* is unstable as the name says and the new implementation is deterministic as the previous one was, but it produces a different equal element ordering than the one before, so a test that relies on one specific order but uses sort_unstable is only valid for one version of Rust.
however, the original problem specifically mentions that it's okay to get either "eert" or "eetr"
I think the correct way to test that would be to do stable sort or assert_matches!(val, "eert" | "eetr").
Looking at the implementation, it sleeps for milliseconds, I fail to see how that could ever work reliably. The OS can decide to wake the threads up at some later point in time, sleep does not guarantee a fixed wakeup time. Plus it doesn't use latches, so it's spawn + sleep before the next thread is spawned. IMO that implementation is just plain broken.
I'm a little surprised by how many instances there are of relying on the order of hashmaps, the order is randomized with the default hasher. Looking at the linked code they seem to be using the default hasher, how come these tests ever reliably work during local development? What am I missing here?
gaffer
Other initial hypothesis is that the library is doing panic recovery. Perhaps some other library in its dep tree is sorting but then panic recovery occurs? survemobility/gaffer@f238bae
I suspect it's just racy. I checked the project out locally and ran cargo t, on my initial run I got:
I really expected that one to be due to sorting issues...
I'm a little surprised by how many instances there are of relying on the order of hashmaps, the order is randomized with the default hasher. Looking at the linked code they seem to be using the default hasher, how come these tests ever reliably work during local development? What am I missing here?
There is a certain sort of person who only ever writes and runs a test once.
I do not mean to accuse, but if they only ran the test a few times, it is possible the hashes happened to work out for them. Even if the hashing perfectly randomizes the keys, if you assert on the order of only 2 items, then it comes up as a coinflip either way. It's reasonable for that to pass 2-4 times in a row if you are lucky.
Would it be possible to add a clippy warning to some code patterns which attempt to assert an expression that depends on hashmap iteration order? Obviously we can't catch everything, but perhaps some of the more common patterns?
changed the title [-]regression: assertion `left == right` for stuff that looks sorting related[/-][+]regression: assertion `left == right` failed because people iterate hashmaps[/+]on Aug 11, 2024
changed the title [-]regression: assertion `left == right` failed because people iterate hashmaps[/-][+]regression: assertion `left == right` failed because of comparisons that depend on library-unstable details[/+]on Aug 11, 2024
changed the title [-]regression: assertion `left == right` failed because of comparisons that depend on library-unstable details[/-][+]regression: assertion `left == right` failed but it depends on library-unstable details[/+]on Aug 11, 2024
It seems unlikely these will all be resolved by the next beta crater run.
In particular, the gaffer tests seem to be completely insoluble as it is an issue in essentially all the tests, so let's just skip that crate's tests from now on.
Activity
workingjubilee commentedon Aug 10, 2024
It is probably the case that these include incorrect sort algorithm impls.
I am bringing these to the attention of @orlp and @Voultapher if they wish to inspect the regressions further.
sort_unstable_byhaving sorted things a certain way, as it only sorts by frequency, not by frequency and then natural order as the tests seem to imply is required: https://github.com/lht102/coding-problems-practice/blob/5b22b46182abe6d0617d087e6b8a0fa22f2edada/leetcode/src/00451_sort_characters_by_frequency/solution.rs#L10-L27ord_correcttest that is now failing, and while I can't find the sort call, it feels likely the answer is wrong or sort may be implicitly called by quickcheck: https://github.com/plaidfinch/hopscotch/blob/54483dabb3252f00f73432984b42bd00f7471466/tests/hopscotch.rs#L136-L146workingjubilee commentedon Aug 10, 2024
I think I am wrong for
somemost, actually.sleep_sortonly. did we change something about concurrency? https://github.com/Chromfalke/AtrociousSort/blob/main/src/algorithms/sleep_sort.rsseems to be another case of asserting after iterating over a hashmap: https://github.com/datdenkikniet/proxmox-api/blob/7d7540839371e3a58837b049997fe5fb8816d0cf/proxmox-api/src/types/multi.rs#L241-L255actually see orlp's comment.bevy_serde_macros
Either way, these do not seem to be directly from the sort changes.
Voultapher commentedon Aug 10, 2024
sort_unstable*is unstable as the name says and the new implementation is deterministic as the previous one was, but it produces a different equal element ordering than the one before, so a test that relies on one specific order but usessort_unstableis only valid for one version of Rust.I think the correct way to test that would be to do stable sort or
assert_matches!(val, "eert" | "eetr").Voultapher commentedon Aug 10, 2024
Looking at the implementation, it sleeps for milliseconds, I fail to see how that could ever work reliably. The OS can decide to wake the threads up at some later point in time, sleep does not guarantee a fixed wakeup time. Plus it doesn't use latches, so it's spawn + sleep before the next thread is spawned. IMO that implementation is just plain broken.
Voultapher commentedon Aug 10, 2024
I'm a little surprised by how many instances there are of relying on the order of hashmaps, the order is randomized with the default hasher. Looking at the linked code they seem to be using the default hasher, how come these tests ever reliably work during local development? What am I missing here?
Voultapher commentedon Aug 10, 2024
I suspect it's just racy. I checked the project out locally and ran
cargo t, on my initial run I got:Which is a completely different test, and the one in the crater run passed. Second run all tests pass.
orlp commentedon Aug 10, 2024
@workingjubilee I find the
proxmox-apicase very strange: https://github.com/datdenkikniet/proxmox-api/blob/7d7540839371e3a58837b049997fe5fb8816d0cf/proxmox-api/src/types/multi.rs#L241-L255Note that the portion of the
serdeoutput that was changed is actually aBTreeMap, not aHashMap.workingjubilee commentedon Aug 10, 2024
@orlp Thanks for catching that! I retract my comments re: "iterating over a hashmap" for that library, but it still seems very odd.
workingjubilee commentedon Aug 10, 2024
Somewhat shockingly, the Project Euler code is also operating with a hashmap: https://github.com/chubei/project_euler/blob/d100bed4c6b7c417276ccba051567c53ed869d40/src/lib.rs#L39-L48
I really expected that one to be due to sorting issues...
There is a certain sort of person who only ever writes and runs a test once.
I do not mean to accuse, but if they only ran the test a few times, it is possible the hashes happened to work out for them. Even if the hashing perfectly randomizes the keys, if you assert on the order of only 2 items, then it comes up as a coinflip either way. It's reasonable for that to pass 2-4 times in a row if you are lucky.
workingjubilee commentedon Aug 10, 2024
I downloaded workpool and reran its tests a few times. It's another racy case. I think we've correctly identified racy library tests in:
And what seem to be definitely hashmap problems:
Unless these are fixed promptly, we should ignore those in future crater runs which cover tests.
Correctly root-caused to the sort impl, but known accepted breakage:
MPCHomeControl is a float problem, so I'll bring it to #128898
That leaves the following as still open questions as to why the test is failing to begin with:
8 remaining items
orlp commentedon Aug 11, 2024
Would it be possible to add a
clippywarning to some code patterns which attempt toassertan expression that depends on hashmap iteration order? Obviously we can't catch everything, but perhaps some of the more common patterns?[-]regression: assertion `left == right` for stuff that looks sorting related[/-][+]regression: assertion `left == right` failed because people iterate hashmaps[/+][-]regression: assertion `left == right` failed because people iterate hashmaps[/-][+]regression: assertion `left == right` failed because of comparisons that depend on library-unstable details[/+][-]regression: assertion `left == right` failed because of comparisons that depend on library-unstable details[/-][+]regression: assertion `left == right` failed but it depends on library-unstable details[/+]workingjubilee commentedon Aug 11, 2024
I guess I retract my retraction regarding proxmox-api???
workingjubilee commentedon Aug 11, 2024
I guess we should test a revert of #125174
workingjubilee commentedon Aug 11, 2024
Hm, #125174 was cratered.
workingjubilee commentedon Aug 11, 2024
The proxmox-api tests may work on the next crater run, so let's not exclude those.
I've opened some PRs and issues on the relevant crates in the hopes of them fixing their code so that we can continue using their test data:
assert!(matches!(expr, pat | pat)lht102/coding-problems-practice#6sleep_sortis incorrect christianschult/AtrociousSort#1pool::collect_into_vectests ggriffiniii/lateral#2It seems unlikely these will all be resolved by the next beta crater run.
In particular, the gaffer tests seem to be completely insoluble as it is an issue in essentially all the tests, so let's just skip that crate's tests from now on.
workingjubilee commentedon Aug 11, 2024
I have opened some followups:
Everything else is accepted breakage, or (hopefully) will be published and fixed for the next beta crater, so I think we're done here.
workingjubilee commentedon Aug 11, 2024
Thank you for playing, everyone!
Auto merge of #732 - workingjubilee:exclude-flakes-found-in-beta-1.81…
Rollup merge of rust-lang#129003 - Voultapher:improve-ord-docs, r=wor…
Unrolled build for rust-lang#129003