Skip to content

Conversation

@orlandohohmeier
Copy link
Member

Add Kademlia (integration) tests, improving the test coverage from 17.95 % (Lines), 35.46 % (Functions) to 82.37 % (Lines), 51.77 % (Functions). Some of the error cases aren't well covered yet.

In case you've never check coverage run the test with the instrument-coverage flag:

RUSTFLAGS="-C instrument-coverage" cargo test

And then generate a report using grcov as follows:

grcov . -s . --binary-path ./target/debug/ --branch --ignore-not-existing -t html

Side Note: Use cargo install --locked grcov) to install grcov if you haven't already.

This will give you a nice html report in ./html that you can open in your browser to understand the coverage.

This is the first PR in a series to improve test coverage pulled from #38

@orlandohohmeier orlandohohmeier requested a review from nfnt July 14, 2025 11:52
@codecov
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

❌ Patch coverage is 96.36364% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/network/tests/kad_test.rs 96.36% 16 Missing ⚠️

📢 Thoughts on this report? Let us know!

@orlandohohmeier orlandohohmeier changed the title Add Kademlia tests add kademlia tests Jul 15, 2025
Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

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

This looks good overall, but let's document why we need sleep in the testing code so that we can remove it in the future.

@orlandohohmeier orlandohohmeier force-pushed the orlandohohmeier/add-kad-tests branch from ede9f6c to b37be08 Compare August 21, 2025 09:46
@orlandohohmeier orlandohohmeier requested a review from nfnt August 21, 2025 09:46
Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -0,0 +1,674 @@
use std::{collections::HashMap, time::Duration};

use futures::StreamExt;
Copy link
Member

Choose a reason for hiding this comment

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

Nit, but a complicated one because of re-exports in multiple packages: IMO, we don't need the futures package at all, because we can find all of it either in futures_util or in tokio. futures re-exports these types from futures_util, the only difference is that it includes an async runtime similar to tokio but which we don't use. I.e. by using futures_util::stream::StreamExt instead and consistently, we can remove a dependency on futures.
tokio also provides its own version of StreamExt, but that ones different from the one in futures_util, missing a lot features.
Right now our code is using all of these in different places and IMO, we should at least remove futures in favor of futures_util, maybe not here but in a separate commit.

@orlandohohmeier orlandohohmeier merged commit a5af690 into main Aug 21, 2025
7 of 8 checks passed
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.

3 participants