-
Notifications
You must be signed in to change notification settings - Fork 398
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
Initialize the env_logger in tests for tracing. #103
Conversation
604d36a
to
8cc4970
Compare
tests/cases/test_raft.rs
Outdated
@@ -425,6 +428,7 @@ impl Network { | |||
|
|||
#[test] | |||
fn test_progress_become_probe() { | |||
let _ = env_logger::try_init(); |
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.
can we use one place to init the logger?
like TiKV CI does https://github.com/tikv/tikv/blob/master/tests/integrations.rs#L63
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.
In a CI you run a full test suite, this is targeted at users trying to trace/debug/log a single or regex'd test.
Once #52 is merged I think we should write the logs of each test to a folder and we can display them nicely when they fail.
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 it is a good style to init logger everywhere. it looks weird.
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.
While I agree, it is the suggested style: https://github.com/sebasmagri/env_logger#in-tests
Regardless, there's no way not to have to init the logger ever test without relying on some test always being run first or something, which breaks cargo test $TEST
workflows.
b3937e0
to
4a1299b
Compare
em, do we need to use |
@siddontang If you are debugging a specific test and have logging enabled, it's not a worry since it's only one test. If you're running the whole bank of tests then we won't log in them. Later when we move to slog we can modify this so that logs for each test go into their own folder, and we can output failed tests. |
seem that tikv uses another way https://github.com/tikv/tikv/blob/master/ci-build/test.sh can we use it yet? IMO, I still don't like adding the initialization to every test function. What we only to do is to output failed case log when CI fails. If we want to trace by ourselves, I think we can add the initialization explicitly and run the test manually. |
@siddontang Unfortunately the testing system in Rust does not have a But we need to do initialization for things like I do not think developers should need to add dependencies ( |
Got it. LGTM PTAL @BusyJay |
@siddontang I will make this call an initializer function and place the |
62cdff8
to
88893fd
Compare
Em @Hoverbear I like your previous way, calling env logger initialization explictly. |
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.
LGTM
Why not keep it as a util function and call it when needed? It looks cumbersome to add it to every test case. And future test cases may probably forget to add the line. |
ping @Hoverbear |
@siddontang I'll rollback then. |
db4586a
to
4d98759
Compare
Ultimately we're discussing two things: First, if we should enable the logger in tests or not. I think in general, in any project, it is a good idea to be able to get the logs for a test without having to change code. I think this is something we can all agree on. In a real situation the logger will be enabled, and since Raft is currently using This means that having the logger enabled could actually change the behavior of a complex high performance system (like TiKV before we used slog). Second, we're discussing how to initialize the logger. Since Rust doesn't provide some sort of Introducing some initialization code to tests is much less invasive and is a good step towards using such a crate in the future if we do want it. Currently we're using the direct call (adding Right now, initializing the logger is just one line ( Perhaps it is worthwhile to do this now, perhaps we will need to do this later. Ultimately though, I think we will need to do this at some point in the future. |
do we need to close it now or merge it? @Hoverbear |
@siddontang If noone is opposed I will redo the work of extracting the log initializer to a function called |
3127ee9
to
688ad58
Compare
Ping @BusyJay @siddontang . Are there any objections you have to this PR? I understand that we'd like a |
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.
LGTM. I'm afraid that this solution might be the simplest one available currently. See also rust-lang/rust#35762 If there are better solutions in future, we can adapt it.
This has two LGTM so I'm merging now. Thanks. :) |
Previously it required some manual intervention to get the logs of a test.
This makes it so, for example,
RUST_LOG=raft=debug cargo test $SOME_TEST_NAME
produces a full log.