-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add test-util
features to hide test utilities
#294
Conversation
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 is a great idea, I was starting to implement this on the task-provisioner PR as well. :)
Another upside of putting the functionality in a test_util
module rather than a separate crate is that the module can access non-public items from the module it is embedded in.
N.B. I think we should go further, e.g. I think we can replace all of the |
Well, this seems like an opportune time to take that one, so I'll take a stab at this and see what it looks like. |
OK -- I think the trickiest bit will be moving the I think everything else should be relatively straightforward? |
There's something here that worries me and that I don't understand. With the current commit (4463aed), if I run
I don't understand why we have |
I'm starting to think this
note the rustc line includes |
Ah, it seems we need |
Note that the text from your second message is from compiling the I think this is OK, though; the behavior I saw when playing with the edit: never mind, doing [1] Line 72 in 40a176d
|
85b97e4
to
2ef69b4
Compare
All right, everything seems to be working now that we have |
janus_server/Cargo.toml
Outdated
@@ -11,6 +11,7 @@ tokio-console = ["console-subscriber"] | |||
jaeger = ["tracing-opentelemetry", "opentelemetry-jaeger"] | |||
otlp = ["tracing-opentelemetry", "opentelemetry-otlp", "opentelemetry-semantic-conventions", "tonic"] | |||
prometheus = ["opentelemetry-prometheus", "dep:prometheus"] | |||
test-util = ["janus_core/test-util", "lazy_static", "testcontainers"] |
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 think this should be dep:lazy_static
& dep:testconatiners
to avoid exposing implicit features lazy_static
& testcontainers
that consumers of the janus_server
crate could enable.
From https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies:
In some cases, you may not want to expose a feature that has the same name as the optional dependency. For example, perhaps the optional dependency is an internal detail, or you want to group multiple optional dependencies together, or you just want to use a better name. If you specify the optional dependency with the dep: prefix anywhere in the [features] table, that disables the implicit feature.
... but it looks like this feature is not available until Rust 1.60 & our Cargo.toml
currently specifies Rust 1.58. If you're (understandably) not comfortable also upgrading our Rust version in this PR, file an issue? Would be a <5 minute cleanup once our Rust version gets bumped, and I think it would be nice to not expose features we don't expect folks to turn on.
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 don't think there's much risk to bumping MSRV to 1.60, since the Rust toolchain installed in GH actions runner is already 1.61, and our container builds are already using rust:1.62.0-alpine
.
@@ -1,23 +0,0 @@ | |||
[package] |
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.
Should the files under src/
in this directory also be removed? I think the code in those files got moved out to various test_util
mods.
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.
The other files were git mv
ed into janus_core/src/test_util
. In my checked out copy of branch timg/test-util-features
, directory $(SRCROOT)/test_util
no longer exists.
657eba7
to
3e4ffca
Compare
We had a handful of items intended for use exclusively in tests that were marked `pub` so that targets like `monolithic_integration_test` can use them, but tagged `#[doc(hidden)]` because they aren't part of the proper public interface to any component of Janus. We now instead hide those test utilities behind a new `test-util` feature defined on crates `janus_core`, `janus_client` and `janus_server`. We could also have moved items to the `test_util` crate but there's something to be said for having e.g. the code that inserts tasks into the datastore be right next to all the other datastore code, instead of `test_util/lib.rs` becoming a dumping ground of items unrelated to each other save that they are used in tests. Additionally, if we ever want to "promote" any of these `test_util` items to being used in production configurations, that's a simple matter of deleting a `#[cfg(feature = "test-util")]` instead of having to move a function and annihilate its git history. Resolves #141
Removes the `test_util` crate, relocating the items it defines to a `test_util` module in `janus_core`, gated by the `test-util` feature. We also set `resolver = "2"` in the top-level `Cargo.toml`, because otherwise crate features get unified between dependencies and dev-dependencies, which cause the release variants of our binary targets to be built with the `test-util` feature (and indeed, before this PR, we were building `tokio` with `test-util` all the time, too!). See [1] for details. [1]: rust-lang/cargo#4866
dfb5122
to
a1e7b62
Compare
We had a handful of items intended for use exclusively in tests that
were marked
pub
so that targets likemonolithic_integration_test
canuse them, but tagged
#[doc(hidden)]
because they aren't part of theproper public interface to any component of Janus. We now instead hide
those test utilities behind a new
test-util
feature defined on cratesjanus_core
,janus_client
andjanus_server
. We could also havemoved items to the
test_util
crate but there's something to be saidfor having e.g. the code that inserts tasks into the datastore be right
next to all the other datastore code, instead of
test_util/lib.rs
becoming a dumping ground of items unrelated to each other save that
they are used in tests. Additionally, if we ever want to "promote" any
of these
test_util
items to being used in production configurations,that's a simple matter of deleting a
#[cfg(feature = "test-util")]
instead of having to move a function and annihilate its git history.
Resolves #141