[Tests] Suppress output in test_bitcoin for expected errors #16277

pull gertjaap wants to merge 1 commits into bitcoin:master from gertjaap:issue-15944 changing 3 files +54 −3
  1. gertjaap commented at 3:21 PM on June 24, 2019: contributor

    Closes #15944

    This adds two methods to noui, that allows temporarily suppressing (and then resuming) the output from noui. For situations where errors are expected, it's confusing for the test binary to output an error and then conclude with No errors detected.

    It also uses this supress/reconnect in the tests that currently produce verbose errors when running test_bitcoin.

    Output of test_bitcoin on current master:

    gertjaap@gjdesktop:~/src/bitcoin$ src/test/test_bitcoin
    Running 351 test cases...
    Error: Specified -walletdir "/tmp/test_common_Bitcoin Core/1561389554_943311758/tempdir/path_does_not_exist" does not exist
    Error: Specified -walletdir "/tmp/test_common_Bitcoin Core/1561389554_643733972/tempdir/not_a_directory.dat" is not a directory
    Error: Specified -walletdir "wallets" is a relative path
    
    *** No errors detected
    

    Output after this code is merged:

    gertjaap@gjdesktop:~/src/bitcoin$ src/test/test_bitcoin
    Running 351 test cases...
    
    *** No errors detected
    
  2. gertjaap renamed this:
    Supress output in test_bitcoin for expected errors
    [Tests] Supress output in test_bitcoin for expected errors
    on Jun 24, 2019
  3. DrahtBot added the label Tests on Jun 24, 2019
  4. DrahtBot added the label Wallet on Jun 24, 2019
  5. practicalswift commented at 6:15 PM on June 24, 2019: contributor

    Concept ACK

    Thanks for working on this: those expected errors are really annoying.

    Nice first-time contribution! Welcome! :-)

  6. DrahtBot commented at 6:56 PM on June 24, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  7. laanwj commented at 11:18 AM on July 1, 2019: member

    Thanks for tackling this, this has been bothering me for a while.

  8. in src/noui.h:25 in cf194cf96a outdated
      18 | @@ -17,4 +19,16 @@ void noui_InitMessage(const std::string& message);
      19 |  /** Connect all bitcoind signal handlers */
      20 |  void noui_connect();
      21 |  
      22 | +/** Suppress all bitcoind signal handlers. Used to suppress output during test runs that produce expected errors */
      23 | +void noui_suppress();
      24 | +
      25 | +/** Non-GUI handlers, which just ignore the message. Connected when calling noui_suppress.
    


    laanwj commented at 11:19 AM on July 1, 2019:

    I don't think there's a need to have these three functions externally exposed in the header, they're only used in noui_suppress


    gertjaap commented at 2:20 PM on July 1, 2019:

    Adjusted

  9. in src/wallet/test/init_tests.cpp:10 in cf194cf96a outdated
       6 | @@ -7,6 +7,10 @@
       7 |  #include <test/setup_common.h>
       8 |  #include <wallet/test/init_test_fixture.h>
       9 |  
      10 | +extern void noui_connect();
    


    laanwj commented at 11:21 AM on July 1, 2019:

    Why are these extern voids here? Doesn't including the header that defines them (noui.h) suffice?


    gertjaap commented at 2:20 PM on July 1, 2019:

    Given the noui_connect() was there when I started, I followed the same convention. Have changed it now, removed the extern voids and included noui.h in stead.

  10. in src/noui.h:8 in cf194cf96a outdated
       4 | @@ -5,6 +5,8 @@
       5 |  #ifndef BITCOIN_NOUI_H
       6 |  #define BITCOIN_NOUI_H
       7 |  
       8 | +#include <boost/signals2/connection.hpp>
    


    laanwj commented at 11:22 AM on July 1, 2019:

    I don't think these includes need to be added here, better include them in the cpp file if they're used there to avoid the boost stuff having to be processed for every compilation unit.


    gertjaap commented at 2:19 PM on July 1, 2019:

    Adjusted

  11. laanwj renamed this:
    [Tests] Supress output in test_bitcoin for expected errors
    [Tests] Suppress output in test_bitcoin for expected errors
    on Jul 1, 2019
  12. gertjaap force-pushed on Jul 1, 2019
  13. gertjaap commented at 2:22 PM on July 1, 2019: contributor

    Addressed review comments and squashed

  14. mzumsande approved
  15. mzumsande commented at 10:49 PM on July 1, 2019: member

    ACK 6d7bcf9, reviewed code and tested his (also checked that reconnect works by suppressing only the first of the three loud tests). Nice to get rid of these error messages, this might also encourage more negative unit tests that people might have shied away from in fear of spamming stderr even more.

  16. in src/noui.cpp:7 in 6d7bcf959a outdated
       3 | @@ -4,15 +4,18 @@
       4 |  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5 |  
       6 |  #include <noui.h>
       7 | -
       8 | -#include <ui_interface.h>
       9 | -#include <util/system.h>
      10 | -
      11 | +#include <boost/signals2/connection.hpp>
    


    MarcoFalke commented at 8:44 PM on July 2, 2019:

    Why is this line moved?


    gertjaap commented at 11:51 AM on July 3, 2019:

    I incorrectly assumed that these imports were alphabetically sorted. This turns out not to be the case. I'll revert this

  17. in src/noui.cpp:74 in 6d7bcf959a outdated
      69 | +    return false;
      70 | +}
      71 | +
      72 | +bool noui_ThreadSafeQuestionSuppressed(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      73 | +{
      74 | +    return false;
    


    MarcoFalke commented at 8:45 PM on July 2, 2019:

    Instead of ignoring the message in the test, shouldn't the test check for the correct messag?


    gertjaap commented at 11:54 AM on July 3, 2019:

    While that's a nice feature to have, this isn't being done currently as well. It would require a much bigger change to achieve that, giving the opportunity to the caller of noui_supress to supply an expected error, or noui_suppress to retain whatever messages are being thrown to it, and adding a method to retrieve them in the test and do assertions on it. I would however prefer to do this in an additional PR on top of this one.


    MarcoFalke commented at 11:58 AM on July 3, 2019:

    Right now at least the test runner can check for the correct reason by reading the stdour (or err). You take that option without providing an alternative.


    practicalswift commented at 12:03 PM on July 3, 2019:

    Is that feature used somewhere?

    If not I suggest that feature can be added when needed.

    Would be nice to get this merged.


    gertjaap commented at 12:10 PM on July 3, 2019:

    I don't think i'm taking any option away: The suppressing only happens when you explicitly call noui_suppress(). So the default is to still print it to stdout, which could be useful if a test needs it. The places that are producing the unwanted output were not using stdout and i'm providing a way for those tests to selectively suppress it.


    MarcoFalke commented at 12:15 PM on July 3, 2019:

    I don't think there is a use case in suppressing the output with no option to read it


    gertjaap commented at 1:03 PM on July 3, 2019:

    The output is not being checked as it stands. If not checking the output is a problem in itself, then that deserves a fix too, but is not the scope of what I was aiming for with this PR.

  18. gertjaap force-pushed on Jul 3, 2019
  19. Suppress output in test_bitcoin for expected errors 7a0c224289
  20. gertjaap force-pushed on Jul 3, 2019
  21. gertjaap commented at 12:11 PM on July 3, 2019: contributor

    Addressed review comment & squashed

  22. laanwj commented at 2:11 PM on July 8, 2019: member

    So a future change after this would be to make it possible to catch the output, and retrieve it for checking, as well as suppressing it. I think that could be done in a future PR and do think this making the test output not contain unexpected errors is an improvement, as-is.

  23. l2a5b1 commented at 3:19 PM on July 9, 2019: contributor

    Suppressing the output is one way to solve the issue.

    However, I don't think that we are addressing the fundamental issue, which is that VerifyWallets doesn't propagate error information to the caller. Instead VerifyWallets keeps that information to itself.

    Functions like VerifyWallets, which don't provide error information to the caller and seem to use logging of the error message as a substitute, should ideally return an expected success or error object to the caller to allow it to handle recoverable errors.

    With a Rust-like Result<T, E> type we can resolve #15944 as follows:

    // VerifyWallet returns an error object of type std::string.
    Result<void, std::string> result = VerifyWallets(...);
    
    // The caller handles recoverable errors in the way it deems appropriate.
    if (error result) {
        log error;
        return;
    }
    

    I dropped WIP code here https://github.com/bitcoin/bitcoin/compare/master...l2a5b1:feature/result-type?expand=1 that shows how we can handle recoverable errors with a Result<T,E> type as an alternative to returning a bool and hiding error information from the caller.

    This code also fixes #15944 but it does this by way of propagating the error information to the caller, allowing the caller to log the error message or to ignore it in the tests.

    If suppressing output is however preferred then this PR seems like a nice way to do it!

  24. MarcoFalke commented at 3:29 PM on July 9, 2019: member

    I do like the idea of a Result type. Are there any C++ libraries that use or offer (or plan to offer) such a type? I.e boost or the standard library.

    This sounds like it would benefit from a project-wide discussion. Maybe open a brainstorming issue or raise the topic in one of the meetings.

  25. laanwj commented at 6:19 PM on July 11, 2019: member

    Yess, I too prefer rust's method of error handling, but I think asking a first-time contributor to rewrite the project's general error-handling methodology is a bit wild, please take that into account here.

  26. KaosGhostNINJA commented at 8:06 PM on July 11, 2019: none

    Already working on fix for that error type scenario may not be exactly the way rust method. I think it will have the same effect will see🤞better then a rewrite anyway.

    On Thu, Jul 11, 2019, 1:23 PM Wladimir J. van der Laan < notifications@github.com> wrote:

    Yess, I too prefer rust's method of error handling, but I think asking a first-time contributor to rewrite the project's general error-handling methodology is a bit wild, please take that into account here.

    — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/pull/16277?email_source=notifications&email_token=AKW4MAX5G66YRWKIPKJCISDP653AJA5CNFSM4H27XUYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZXRXEY#issuecomment-510598035, or mute the thread https://github.com/notifications/unsubscribe-auth/AKW4MAV3Q4B6G63HEADGSTTP653AJANCNFSM4H27XUYA .

  27. gertjaap commented at 10:23 AM on July 17, 2019: contributor

    I like the suggestion @l2a5b1 made, of a Result<T, E> return value to functions that now return bool and don't propagate error info. I think the project would benefit a lot from something like that. That said, it seems like something we should discuss in broader perspective as @MarcoFalke suggested. I'd be happy to contribute to that discussion and/or help implementing the preferred solution.

    I enjoy thinking about larger refactoring as much as the next guy, and if this PR triggers a broader discussion that ends up improving Bitcoin's error-handling, then I'll take that as a win. I do however think that this broader discussion might take time and effort, where this PR provides an - in my view - acceptable solution to the problem it's addressing today, and is solving something people are actually annoyed by for some time.

  28. l2a5b1 commented at 10:01 PM on July 19, 2019: contributor

    ACK 7a0c224 - tested and reviewed.

    Thanks @gertjaap! I will take the suggestion pertaining to propagating errors somewhere else.

  29. in src/noui.cpp:97 in 7a0c224289
      95 | +{
      96 | +    noui_ThreadSafeMessageBoxConn.disconnect();
      97 | +    noui_ThreadSafeQuestionConn.disconnect();
      98 | +    noui_InitMessageConn.disconnect();
      99 | +    noui_connect();
     100 | +}
    


    l2a5b1 commented at 11:09 AM on July 20, 2019:

    Add newline :)

  30. laanwj commented at 1:17 PM on August 1, 2019: member

    ACK 7a0c2242890549b6dddac4cc6f1840a528469f2a

  31. laanwj merged this on Aug 1, 2019
  32. laanwj closed this on Aug 1, 2019

  33. laanwj referenced this in commit e653eeff76 on Aug 1, 2019
  34. sidhujag referenced this in commit a7bfd259ad on Aug 1, 2019
  35. pingwindyktator referenced this in commit 12ea14397a on Feb 27, 2020
  36. kittywhiskers referenced this in commit 10e225dcc4 on Oct 8, 2021
  37. kittywhiskers referenced this in commit 805aeac77b on Oct 12, 2021
  38. kittywhiskers referenced this in commit 6fe55d44ee on Oct 16, 2021
  39. kittywhiskers referenced this in commit 29c4f19b36 on Oct 16, 2021
  40. kittywhiskers referenced this in commit f355ed49f6 on Oct 19, 2021
  41. PastaPastaPasta referenced this in commit 07632958cb on Oct 20, 2021
  42. pravblockc referenced this in commit 69956cf3fb on Nov 18, 2021
  43. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me