-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: Add ASSERT_DEBUG_LOG to unit test framework #16540
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
fa79298 to
fa3cd66
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
fa6aeeb to
fae9929
Compare
3333dee to
fa98bd1
Compare
|
Concept ACK |
fac57b4 to
fad4319
Compare
|
re-run ci |
|
Concept ACK. I think this might be better if implemented with a RAII approach, so you write: and an error appears if the string wasn't found by the end of the block. See https://github.com/ajtowns/bitcoin/commits/201910-assertdebuglog for a patch. This way avoids the globals and lets you just do two asserts in the same block rather than having to always create a vector. I also changed it so it only captures the log if you say |
fad4319 to
faa78a6
Compare
|
Thanks, taken some of the patch and rebased |
faa78a6 to
fafa1b9
Compare
|
If I change |
|
@ajtowns This is an issue every time an The correct error is still printed and the tests fail. I am not sure how to fix this minor usability issue, given that the logger is global (shared state) and the |
fafa1b9 to
fa2c44c
Compare
|
Rebased |
|
ACK fafa1b931ad9a69922bac53fb0a49d568719c2c2 |
|
@laanwj Any objections? Otherwise I will merge tomorrow |
fa2c44c test: Add ASSERT_DEBUG_LOG to unit test framework (MarcoFalke) fa1936f logging: Add member for arbitrary print callbacks (MarcoFalke) Pull request description: Similar to `assert_debug_log` in the functional test framework Top commit has no ACKs. Tree-SHA512: aa9eaeca386b61d806867c04a33275f6eb4624fa5bf50f2928d16c83f5634bac96bcac46f9e8eda3b00b4251c5f12d7b01d6ffd84ba8e05c09eeec810cc31251
| noui_reconnect(); | ||
| LogInstance().DeleteCallback(m_print_connection); | ||
| if (!m_found) { | ||
| throw std::runtime_error(strprintf("'%s' not found in debug log\n", m_message)); |
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.
Haven't looked closely, but I'm kind of surprised you can get away with throwing an exception in a destructor (check_found is called by ~DebugLogHelper).
If this works, it seems fine. But in case there are issues, an alternative could be to use a callback instead of a scope, so instead of:
{
ASSERT_DEBUG_LOG("Please check that your computer's date and time are correct!");
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5
}Something like:
AssertDebugLog("Please check that your computer's date and time are correct!", [&] {
MultiAddTimeData(1, DEFAULT_MAX_TIME_ADJUSTMENT + 1); //filter size 5
});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 believe C++11 makes destructors implicitly noexcept, which means that an uncaught exception from results in std::terminate() being called, which is what we want from throwing a runtime exception anyway
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 forgot about this, but indeed the test seem to fail either way, which is what we want.
Summary: * logging: Add member for arbitrary print callbacks * test: Add ASSERT_DEBUG_LOG to unit test framework This is a backport of Core [[bitcoin/bitcoin#16540 | PR16540]] Test Plan: make check Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D5909
Similar to
assert_debug_login the functional test framework