Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate test flakes in recently-added heap tests #65

Merged
merged 2 commits into from
Apr 19, 2024
Merged

Conversation

jhump
Copy link
Member

@jhump jhump commented Apr 19, 2024

Perhaps the sift up/down ops inside the heap impl are not entirely deterministic? It seemed rather consistent in my tests, and has mostly been true in CI. And yet there were also these two failures 🤔:

https://github.com/bufbuild/httplb/actions/runs/8754637253/job/24026890423
https://github.com/bufbuild/httplb/actions/runs/8755567093/job/24029992149

So this adjusts the test to not care about precise order. Instead, it only cares about distinctness of the items picked.

Edit: source of non-determinism was use of a map inside the implementation of update, nothing to do with any non-determinism in the container/heap package.

Copy link
Member

@jchadwick-buf jchadwick-buf left a comment

Choose a reason for hiding this comment

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

I'm a bit skeptical that the heap ops could play into this; the bin heap implementation in Go is very straight-forward and I don't think it should be non-deterministic at all. I think if anything it must be caused by map iteration order somewhere (range over newMap?) That said, if we're not picky about it being deterministic, no need to really think about it too much. LGTM.

(edit: I am curious though, heaps certainly must not have an absolute order since heaps are only partially ordered, so there must be multiple orders that all satisfy the heap ordering property, right? I guess even if it was fully ordered, though, non-determinism could still cause issues if the Less() function is not stable.)

@jhump
Copy link
Member Author

jhump commented Apr 19, 2024

range over newMap

🤦, yes, that's exactly what it is. Great observation! That's why on both failed runs it doesn't show up until later in the test, and it's always between "g" and "h" (two elements in the map, so some iterations they are inserted in one order, others the opposite order).

@jhump jhump merged commit 605a5a8 into main Apr 19, 2024
6 checks passed
@jhump jhump deleted the jh/avoid-flakes branch April 19, 2024 17:00
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.

2 participants