Extra test for rust-libp2p ping protocol by haxxpop · Pull Request #3242 · shadow/shadow · GitHub
Skip to content

Extra test for rust-libp2p ping protocol - #3242

Open
haxxpop wants to merge 1 commit into
shadow:mainfrom
haxxpop:libp2p-ping
Open

haxxpop wants to merge 1 commit into
shadow:mainfrom
haxxpop:libp2p-ping

Conversation

@haxxpop

@haxxpop haxxpop commented Dec 5, 2023 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@haxxpop

haxxpop commented Mar 5, 2024

Copy link
Copy Markdown
Contributor Author

@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

stevenengler commented Mar 11, 2024 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread src/test/Cargo.toml
once_cell = "1.19.0"
vasi-sync = { path = "../lib/vasi-sync" }
static_assertions = "1.1.0"
tokio = { version = "1.34.0", features = ["full"] }

@stevenengler stevenengler Mar 18, 2024 •

Copy link
Copy Markdown
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

@stevenengler stevenengler Mar 18, 2024 •

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.)

Copy link
Copy Markdown
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.

2 participants