-
Notifications
You must be signed in to change notification settings - Fork 146
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
#2896: Made the test more concrete #2917
#2896: Made the test more concrete #2917
Conversation
Pattern : Difference is in |
@levBagryansky Apparently, It has a concurrency issue. I guess the key problem is in this peace of code, /**
* Initialize the appender.
* Adds appender to the root logger.
*/
void init() {
final Logger logger = LogManager.getRootLogger();
final Enumeration<?> appenders = logger.getAllAppenders();
if (appenders.hasMoreElements()) {
final Object next = appenders.nextElement();
if (next instanceof ConsoleAppender) {
this.setLayout(((Appender) next).getLayout());
}
}
logger.addAppender(this);
this.logs.waitForInit();
} As you can see, we have |
@levBagryansky Also note, that logging is actually an asynchronous process. So you might need to "wait" when the desired log will be captured. |
@volodya-lombrozo maybe we can use unique |
@levBagryansky In this case you might not see the results in your console. The idea is to append "unique" logger appender over the default console logger. |
@volodya-lombrozo We should make it the way that |
@volodya-lombrozo I have an Idea to do it this way
But a test can use different threads inside. |
@levBagryansky Yes, it would be great. As for:
I'm afraid it might be too dangerous and error-prone to count on thread names here. I guess we need to understand what we can do on the slf4j level instead. |
@volodya-lombrozo I don't see any option how to distinguish messages from different tests. They can be from different threads and we cannot "tag" them somehow. |
@levBagryansky Actually it's a good idea, as for me! I mean this "tagging". However, maybe we can use something different, instead of creating temporary folders (I guess it might be rather slow to constantly touch a filesystem)? Maybe we can use |
@volodya-lombrozo Idea with temps is based on the fact that messages with |
@levBagryansky I see. To be honest, I don't like this solution because:
Hence, if we don't have any other option, we might try to implement it as you suggested, but I would suggest to dig a bit dipper and solve the original concurrency problem with log appenders. |
@volodya-lombrozo pls review |
eo-maven-plugin/src/test/java/org/eolang/maven/log/CaptureLogs.java
Outdated
Show resolved
Hide resolved
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.
@levBagryansky Looks good to me. Thank you for your contribution!
@yegor256 Please take a look |
@yegor256 please check |
1 similar comment
@yegor256 please check |
@yegor256 please check. I filter the logs by temp path in order to avoid getting messages from other tests. |
@yegor256 please check |
@yegor256 please merge |
1 similar comment
@yegor256 please merge |
@yegor256 please check |
@rultor merge |
Closes #2896
Now
Logs
get all messages, from other tests too. Thus, here we changed the test so now it filter messages by temp path too,PR-Codex overview
This PR improves thread safety by making
@CaptureLogs
annotation specific to each test.Detailed summary
@CaptureLogs
thread-safe to contain only test-related logsorg.hamcrest
imports for assertionsVerifyMojoTest