Skip to content

Tests now each run in their own netns#20

Merged
cathay4t merged 3 commits into
rust-netlink:mainfrom
yonatan-linik:netns_per_test
May 25, 2026
Merged

Tests now each run in their own netns#20
cathay4t merged 3 commits into
rust-netlink:mainfrom
yonatan-linik:netns_per_test

Conversation

@yonatan-linik

Copy link
Copy Markdown
Contributor

Also adds convenience functions to make tests shorter

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the test suite to utilize network namespaces for better isolation, replacing legacy command execution helpers with a new NetnsGuard utility. It also updates the bond interface data model to use optional fields and refines the vxlan display output. Key feedback includes correcting a syntax error in a test helper's return type, addressing a potential string slicing issue in timer normalization, and cleaning up commented-out code.

Comment thread src/ip/address/tests/address.rs Outdated

// Skip whitespace
let whitespace_len =
remaining.chars().take_while(|c| c.is_whitespace()).count();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using chars().count() to determine a byte index for slicing is dangerous because it returns the number of Unicode scalar values, not the number of bytes. While it may work here if the characters are all ASCII, it is better practice to use byte-oriented methods like find to ensure the index is valid for slicing.

            let whitespace_len = remaining.find(|c: char| !c.is_whitespace()).unwrap_or(remaining.len());

Comment thread src/ip/tests/netns.rs Outdated
@yonatan-linik yonatan-linik force-pushed the netns_per_test branch 3 times, most recently from 41bf1f4 to 4650e3d Compare May 23, 2026 13:41
@yonatan-linik yonatan-linik marked this pull request as ready for review May 23, 2026 13:43
@cathay4t

cathay4t commented May 24, 2026

Copy link
Copy Markdown
Member

@yonatan-linik Before you spend more time on this. Could you explain why we need to run tests in isolated namespace and why we cannot live with current test design?

@yonatan-linik

yonatan-linik commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

@yonatan-linik Before you spend more time on this. Could you explain why we need to run tests in isolated namespace and why we cannot live with current test design?

@cathay4t Running each test in its own namespace makes sure there are no name collisions (or other unique values) and allows for guaranteed cleanup of all resources with netns deletion.
For example, some specific test in the address suite can add another interface and not worry about cleanup.
The current design requires us to not repeat interface names (and possibly other values) across all tests in the system which is possible, but can become difficult when the scale of tests gets larger.

@cathay4t

Copy link
Copy Markdown
Member

Good point. Now we need to wrap it into simpler design to make follow-up contributors life easier.

@yonatan-linik

Copy link
Copy Markdown
Contributor Author

@cathay4t Simpler than what I have in this PR?
Do you have a suggestion?
Or should this simplification be done in a separate PR?

The spaces were in a place that can cause a double space if some fields
are missing.

Like this:
```
vxlan id 6671 srcport 0 0 dstport 25758 ttl auto ageing 300  addrgenmode eui64
                                                           ^^
```
@cathay4t

Copy link
Copy Markdown
Member

It is good enough.

Since you are using namespace for each tests now, please modify the tests to use the same test interface name.

@yonatan-linik

Copy link
Copy Markdown
Contributor Author

@cathay4t I already did, unless you see I missed some file.

@cathay4t

Copy link
Copy Markdown
Member

All set. Thanks for the great work!

@cathay4t cathay4t merged commit ed1d804 into rust-netlink:main May 25, 2026
3 checks passed
@yonatan-linik yonatan-linik deleted the netns_per_test branch May 25, 2026 06:14
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.

2 participants