-
Notifications
You must be signed in to change notification settings - Fork 27
Add integration tests #4
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
Conversation
* Test payload * Improve iface.send()
@vorner Do you think it's better to configure the tun device in the test? I didn't do that because those commands should be run as root. And do you know how to configure the device in the CI environment? |
Sorry, I don't have the time to look at it right now. Hopefully over the weekend I might find some. |
@vorner No problem. Take your time. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, the missing Drop
implementation closing the file descriptor is a bug. Do you want to fix it, or should I?
As for the commands, I'd probably say that the test should do them and start without a pre-created tun. The Iface
constructor creates a new tuntap device if it doesn't exist ‒ see the examples. Furthermore, you might want to allow the kernel to include a sequence number in the name (eg. testtun%d
), so the tests running in parallel won't disrupt each other.
I think the CI will have to be configured to allow to run with privileged docker or in non-docker environment. I think I've seen some documentation in travis that allows such thing.
A little style thing: as these are more of integration tests than unit tests, would you move them into a separate file in the tests
directory?
As for the etherparse crate, thanks for bringing it to my attention. I've usually used pnet-packet for such things, but this one seems more lightweight. I'll definitely want to have a look at it.
src/lib.rs
Outdated
@@ -221,3 +221,10 @@ impl IntoRawFd for Iface { | |||
self.fd.into_raw_fd() | |||
} | |||
} | |||
|
|||
impl Drop for Iface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vorner I tried to fixed it. But the compiler says:
error[E0509]: cannot move out of type `Iface`, which implements the `Drop` trait
--> src/lib.rs:221:9
|
221 | self.fd.into_raw_fd()
| ^^^^^^^
| |
| cannot move out of here
| move occurs because `self.fd` has type `std::fs::File`, which does not implement the `Copy` trait
I couldn't create tuntap device in Docker. I'm running this on a VM. |
To create a TunTap device with |
Sorry, it's not a bug. You just reminded me that the tests were run in parallels. With |
Ah, I see. The For the test, I agree that it makes sense to not make it work in parallel and run them sequentially. It would be nice, though, to be able to just do The same reason (running on random developer's computer) would still apply to generating the name from within the test, somehow dynamically as opposed to using hardcoded I do find an argument that in practice you might want to use a pre-created one, nevertheless, these are tests and convenience of running (and cleanup) probably wins over security. The tun in docker ‒ it should be possible, but you need to run the docker in privileged mode. (Sorry for somewhat chaotic answer, I still didn't find enough time to think about it thoroughly) |
How did you do that? Is a crate required? rust-lang/rust#43155 |
Yes, something like once-cell or lazy_static (I personally prefer the first, it has nicer API). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for nitpicking that much and that it takes such a long time, but I kind of can't help it 😇. I'm starting to more or less like the current version, there are still some details.
Some slightly bigger topics:
- I'm still not entirely happy about the manual setup of the tun, and that it's
tun0
which might be actually used on a developer computer. I won't insist on tests setting it themselves, but at least:- Use some different name, please, one that's less likely to be taken. Maybe
tun-test-0
. - It would be nice if someone run this on their own computer (not on CI), they would get a hint/the right error message. As a suggestion, I'd say add another test case called
system_setup_correctly
that would check the correct tun exists and if not, it would error out with explaining message and hint what to do (or maybe at least reference a comment in the code how to set it up). I wouldn't fancy issues opened stating tests fail only to find out someone didn't set up environment for the test.
- Use some different name, please, one that's less likely to be taken. Maybe
- We'll need to somehow clean up the git history before merging. Let's leave it with adding commints during the review, but some kind of rewrite/rebase will have to happen. Will you want to do it yourself, or will you leave it up to me?
Cargo.toml
Outdated
@@ -31,3 +31,4 @@ tokio-core = { version = "~0.1", optional = true } | |||
[dev-dependencies] | |||
version-sync = "~0.5" | |||
etherparse = "0.9.0" | |||
serial_test = "0.3.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, this is cool :-). Didn't know about that one.
I've noticed version 0.4 came out yesterday, maybe this could be used.
Anyway, looking at the dependencies, I know this is only a style point (valid for the etherparse above too):
- I prefer to prefix them with the tilde (
~
). This is the same as no prefix, but it is cleaner in stating the version required is not exact, but only semver-compatible. - I omit the last digit that's not needed, to give the resolver as much freedom as possible. For etherparse, the
0
at the end is not needed for sure. Do you need some specific changes/bugfixes inserial_test 0.3.2
, or any0.3
would do? (or 0.4)?
tests/integration_test.rs
Outdated
assert_eq!(_ip_header.source, [10, 10, 10, 1]); | ||
assert_eq!(_ip_header.destination, [10, 10, 10, 2]); | ||
assert_eq!(_udp_header.source_port, 2424); | ||
assert_eq!(_udp_header.destination_port, 4242); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again, why are the variable names with _
? Using them in assert counts as use, so you shouldn't get an unused variable lint, and especially in tests, checking them is the intended use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got compiler warnings for having variable names like ip_header
. _
prefix was the compiler proposed. After upgraded to 1.40 the warnings were gone.
Sorry, I'm a little busy recently. I will make the changes when I'm available. Thanks for reviewing. |
And I'm glad you are picky because I'm new in Rust, so don't worry about it. |
And add the shell script to create and to delete the device.
Come to think about it again, I still don't feel running
Is it possible to squash all the commits into one when you merge it? (I thought I saw this feature somewhere) Otherwise I can rebase it if you are not available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to squash all the commits into one when you merge it?
Yes, that's a possibility. It couldn't be used if you wanted to preserve multiple commits with related changes but somewhat separate, but I think in this case one commit is good.
Should I use the commit message of the first one?
Anyway, I'm happy with the current version. There's this one language correction which I might as well do myself when merging it. So, I'll just wait for you to confirm that you're OK with the current state too and then go ahead.
|
||
sudo ip tuntap add dev tun10 mode tun user $(whoami) | ||
sudo ip address add 10.10.10.1/24 dev tun10 | ||
sudo ip link set tun10 up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires sudo
to be available, as opposed to some other ways of setting this up (eg. running it directly as root). But I guess it's OK to live with it this way; people with really unusual systems might at least use the script as an inspiration.
I think it's ok to use the message of the first commit. Thanks. |
Thank you. And sorry it took so long. |
The tests require a
tun0
device with address10.10.10.1/24
in the OS. On Debian, you can set it up like this:Please let me know if this is acceptable.
Currently the two tests can only pass one because the
Iface
doesn't close the device file. Could it be a bug?