Skip to content

Fix test failure on Rust v1.81#6407

Merged
mergify[bot] merged 2 commits intosigp:unstablefrom
eserilev:fix-peer-test
Sep 19, 2024
Merged

Fix test failure on Rust v1.81#6407
mergify[bot] merged 2 commits intosigp:unstablefrom
eserilev:fix-peer-test

Conversation

@eserilev
Copy link
Copy Markdown
Member

@eserilev eserilev commented Sep 17, 2024

Issue Addressed

#6405

Proposed Changes

prevent NaN f64 by looping through f64::arbitrary calls until we get a valid number

@eserilev eserilev added bug Something isn't working test improvement Improve tests labels Sep 17, 2024
attestation_net_bitfield,
sync_committee_net_bitfield,
score: f64::arbitrary(g),
score: rand_f64(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quickcheck (and proptest) can do a clever thing called shrinking where they simplify (shrink) failing test cases to be as small as possible. If we mix in rand we are taking control from quickcheck which will make the test non-deterministic based on quickcheck's seed and will disable shrinking.

I think it might be better to use f64::arbitrary in a loop until it returns a value other than NaN. An even cleaner option might be generating floats in a range, which would also avoid other weird values like infinity. From a quick skim of the docs I'm not sure if quickcheck's arbitrary has a function for this though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could do the NaN loop for now and then come back to this if/when we rewrite our quickcheck tests using proptest. Proptest is a bit better maintained

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks for the additional context!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@eserilev eserilev added the ready-for-review The code is ready for review label Sep 18, 2024
Copy link
Copy Markdown
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

can instead we do something like

diff --git a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs
index c8425fc10..b36bccfed 100644
--- a/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs
+++ b/beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs
@@ -335,9 +335,14 @@ impl PartialOrd for Score {
 
 impl Ord for Score {
     fn cmp(&self, other: &Score) -> std::cmp::Ordering {
-        self.score()
-            .partial_cmp(&other.score())
-            .unwrap_or(std::cmp::Ordering::Equal)
+        match (self.score(), other.score()) {
+            (s, o) if o.is_nan() || s.is_nan() => std::cmp::Ordering::Equal,
+            (_s, o) if o.is_nan() => std::cmp::Ordering::Greater,
+            (s, _o) if s.is_nan() => std::cmp::Ordering::Less,
+            (s, o) => s
+                .partial_cmp(&o)
+                .expect("all possible panic cases are covered"),
+        }
     }
 }

and address the broken Ord impl?

@eserilev
Copy link
Copy Markdown
Member Author

the custom ordering implementation you suggested doesn't seem to resolve the issue. Not 100% sure why, I'll have some time this evening to dig into this a bit further

@michaelsproul
Copy link
Copy Markdown
Member

@eserilev @jxs That Ord impl doesn't work because NaN == NaN is false.

There's also a typo in the first match arm. I'm guessing you meant o.is_nan() && s.is_nan(). Even with that change, it won't work because we'll have partial_cmp(s, o) = Some(Equal) but s != o because they are both NaN.

I'm going to merge this PR as-is because CI is now blocked on it since the runners were updated to v1.81.

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Sep 19, 2024
@michaelsproul
Copy link
Copy Markdown
Member

@mergify queue

@mergify
Copy link
Copy Markdown

mergify bot commented Sep 19, 2024

queue

🛑 The pull request has been removed from the queue default

Details

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

@michaelsproul
Copy link
Copy Markdown
Member

@mergify refresh

@mergify
Copy link
Copy Markdown

mergify bot commented Sep 19, 2024

refresh

✅ Pull request refreshed

@michaelsproul
Copy link
Copy Markdown
Member

@mergify queue

@mergify
Copy link
Copy Markdown

mergify bot commented Sep 19, 2024

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 8a085fc

@mergify mergify bot merged commit 8a085fc into sigp:unstable Sep 19, 2024
jxs added a commit to jxs/lighthouse that referenced this pull request Sep 20, 2024
jxs added a commit to jxs/lighthouse that referenced this pull request Sep 20, 2024
jxs added a commit to jxs/lighthouse that referenced this pull request Sep 20, 2024
jxs added a commit to jxs/lighthouse that referenced this pull request Sep 20, 2024
jxs added a commit to jxs/lighthouse that referenced this pull request Sep 24, 2024
mergify bot pushed a commit that referenced this pull request Sep 25, 2024
* drop score Ord, PartialOrd, Eq and PartialEq impls

and impl total_cmp instead

* Revert "Fix test failure on Rust v1.81 (#6407)"

This reverts commit 8a085fc.

* reverse in the compare function

* lint mdfiles
chong-he pushed a commit to chong-he/lighthouse that referenced this pull request Nov 26, 2024
* generate rand f64 instead of arbitrary to prevent NaN vals

* reintroduce quickcheck arbitrary but prevet NaN
chong-he pushed a commit to chong-he/lighthouse that referenced this pull request Nov 26, 2024
* drop score Ord, PartialOrd, Eq and PartialEq impls

and impl total_cmp instead

* Revert "Fix test failure on Rust v1.81 (sigp#6407)"

This reverts commit 8a085fc.

* reverse in the compare function

* lint mdfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-merge This PR is ready to merge. test improvement Improve tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants