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

Extra test for rust-libp2p ping protocol #3242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ppopth
Copy link
Contributor

@ppopth ppopth commented Dec 5, 2023

As discussed in #3201, this PR is the first PR to add extra tests for rust-libp2p. It includes only the simple libp2p ping protocol. More advanced libp2p protocols (such as gossipsub) will come later.

Note that this PR depends on netlink sockets, as implemented in #3198, and linux-specific edge-triggered epoll, as discussed in #2673 and implemented in #3243 (previously in #2675).

So both of them have to be merged first before this test can pass.

Thank you.

@github-actions github-actions bot added Component: Testing Unit and integration tests and frameworks Component: Build Build/install tools and dependencies labels Dec 5, 2023
This was referenced Dec 5, 2023
@stevenengler
Copy link
Contributor

Just adding a comment that we're waiting on the epoll and netlink PRs to be merged before we look at this one.

I think one thing we'll want to change is to make the build conditional on the "--extra" flag. This PR adds a number of larger dependencies like tokio which increase shadow's build time, so since these tests only run in the "extra" configuration, we'd want them to only build in the "extra" configuration as well. We briefly discussed some possibilities for how to do this (cargo feature flags, cargo examples, etc) and we hadn't decided what method would be best. But we can consider this more in-depth once the epoll and netlink PRs are closer to being merged.

@ppopth
Copy link
Contributor Author

ppopth commented Mar 5, 2024

@stevenengler Since the epoll PR and netlink PR have been merged, do you have a plan for this PR?

Side question. Do you think this should be an extra test? Is there any chance this can be a non-extra one?

@stevenengler
Copy link
Contributor

stevenengler commented Mar 11, 2024

Side question. Do you think this should be an extra test? Is there any chance this can be a non-extra one?

Since this is a libp2p compatibility test, I'm leaning towards this being an extra test like the other compatibility tests such as tor, tgen, golang, the examples, etc. And then leaving the default tests to be just system call tests and other small tests. We do run all extra tests in the CI though, so any changes that break your libp2p tests would be caught before merging any future PRs.

This PR adds quite a few dependencies to the tests (from 207 to 341 compilation units) and increases the build time of the tests from 65 seconds to 99 seconds.[1] Shadow's build time is already painfully long, so I think it would be best to avoid increasing it by a lot in the default case unless there's a strong argument for it.

For users that want to run only the libp2p tests, they should be able to use ./setup test --extra libp2p.

[1] If #3304 is applied (both to shadow and this PR), the compilation units increase from 150 to 285 and the build time increases from 42 seconds to 71 seconds.

@stevenengler Since the epoll PR and netlink PR have been merged, do you have a plan for this PR?

I opened a discussion post about building the extra tests at #3305.

@stevenengler
Copy link
Contributor

@stevenengler Since the epoll PR and netlink PR have been merged, do you have a plan for this PR?

I opened a discussion post about building the extra tests at #3305.

I merged #3309 which should allow you to make the test in this PR an extra test by:

  1. adding required-features = ["extra_tests"] to the test_libp2p_ping bin in Cargo.toml
  2. make the new dependencies (futures, libp2p, and tokio) optional in Cargo.toml using optional = true and changing the extra_tests feature to extra_tests = ["dep:futures", "dep:libp2p", "dep:tokio"]
  3. not running the new test by default using set_property(TARGET libp2p-ping PROPERTY EXCLUDE_FROM_ALL true) and add_dependencies(extra_tests libp2p-ping)

If you have any questions, let me know.

@@ -229,3 +235,4 @@ signal-hook = "0.3.17"
once_cell = "1.19.0"
vasi-sync = { path = "../lib/vasi-sync" }
static_assertions = "1.1.0"
tokio = { version = "1.34.0", features = ["full"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the "full" feature needed, or is there a smaller set of features that could be used instead?

text="Listening on \"/ip4/1.1.1.2/tcp/9001\""
cat ./hosts/peer2/*.stdout | grep "$text"

expected_ping_count=20
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the expected count 20? Can you add a comment?

async fn main() -> Result<(), Box<dyn Error>> {
// Usage: ./test_libp2p_ping [listen-port] [peer-multiaddr]

let mut swarm = libp2p::SwarmBuilder::with_new_identity()
Copy link
Contributor

Choose a reason for hiding this comment

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

For those of us who aren't familiar with libp2p, can you add a few more comments about what the program is doing, and what things like noise::Config::new and yamux::Config::default are used for?

expected_ping_count=20
regex="Event { peer: PeerId(.*), connection: ConnectionId(.*), result: Ok(.*) }"

actual_ping_count=$(cat ./hosts/peer1/*.stdout | grep "$regex" | wc -l)
Copy link
Contributor

Choose a reason for hiding this comment

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

From the shell lint check:

 actual_ping_count=$(cat ./hosts/peer1/*.stdout | grep "$regex" | wc -l)
                                                 ^-----------^ SC2126 (style): Consider using grep -c instead of grep|wc -l.

(And for the other grep | wc below.)

loop {
match swarm.select_next_some().await {
SwarmEvent::NewListenAddr { address, .. } => println!("Listening on {address:?}"),
SwarmEvent::Behaviour(event) => println!("{event:?}"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the verify.sh script searches for this println and depends on the formatting of it, can you add a match case for SwarmEvent::Behaviour(libp2p::ping::Event(event)) that formats the output in some explicit way. This way if the debug formatting changes for libp2p::ping::Event, it won't cause the regexes to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Build Build/install tools and dependencies Component: Testing Unit and integration tests and frameworks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants