nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.65k stars 665 forks source link

Revisit test_mount's test runner #248

Open kamalmarhubi opened 8 years ago

kamalmarhubi commented 8 years ago

231 enables mount. The test includes a hackish little macro-based test runner because the user and mount namespaces must be entered with unshare(2) before any threads spawn, and the built in test runner doesn't allow that.

Relevant bit of unshare(2) man page:

`CLONE_NEWUSER` requires that the calling process is not
threaded; specifying `CLONE_NEWUSER` automatically implies
`CLONE_THREAD`.

It would be better if we could use the default test runner, but this is not possible right now. We'd need either:

  1. the ability to specify RUST_TEST_THREADS=1 for this test from Cargo.toml, and then call unshare(2) from use sync::Once at the start of each test to ensure we've already entered the namespaces
  2. the ability to run setup code before the test harness spawns any threads

I think both are worthwhile options, but for this use case 2. would be nicer, as it would then allow the tests to run in concurrently which might be quicker.

kamalmarhubi commented 8 years ago

I just remembered I filed https://github.com/rust-lang/rfcs/issues/1442 almost a month ago because of this issue! I'm going to try and see if this is feasible.