test: add comprehensive unit tests for ring module #2261
Merged
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.
Problem
The ring module had low test coverage in several key files:
connection_manager.rs: 22.1%peer_key_location.rs: 18.0%location.rs: 64.0%score.rs: 0% (not even included in mod.rs)Additionally, the
Scoretype'sOrdimplementation had a potential bug wherepartial_cmp().unwrap_or(Equal)would treat NaN values as equal to everything, violatingOrdrequirements.Solution
Bug Fix
Score::Ordto usetotal_cmp()for consistent NaN handling. The previous implementation would cause undefined behavior in sorting algorithms when NaN values were present.New Tests (~100 tests added)
score.rs (8 tests):
location.rs (~35 tests):
peer_key_location.rs (~25 tests):
connection_manager.rs (~30 tests):
should_acceptlogic (min/max connections, already connected peers)Test Plan
[AI-assisted - Claude]